Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding createIfDeferred to ImageResult #2322

Closed
m-vo opened this issue Sep 21, 2020 · 0 comments · Fixed by #2368
Closed

Consider adding createIfDeferred to ImageResult #2322

m-vo opened this issue Sep 21, 2020 · 0 comments · Fixed by #2368

Comments

@m-vo
Copy link
Member

m-vo commented Sep 21, 2020

We should imo consider adding a createIfDeferred method (working like the one in File) to the ImageResult class as well, so that you can easily use the FigureBuilder concept for documents, emails or other occations where the result shouldn't be fetched from the server.

@leofeyer leofeyer closed this as completed Oct 1, 2020
leofeyer pushed a commit that referenced this issue Oct 14, 2020
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Closes #2322
| Docs PR or issue | Todo

This adds the ability to synchronously trigger the creation of resized images from within an `ImageResult`. This is similar to `File#createIfDeferred()` but processes all resources (picture img + picture sources) instead of a single file.

Contrary to the method in `File` an exception will be thrown if the `contao.image.resizer` service does not support deferred resizing (`DeferredResizerInterface`) and exceptions won't be swallowed.

**Demo Usage:**
```php
$figure = $studio->createFigureBuilder()
    ->fromPath('files/public/foo.jpg')
    ->setSize('_my_size')
    ->build();

$figure->getImage()->createIfDeferred();

// It's now safe to access any of the generated image files directly
$pdf->addImage($figure);
```

Commits
-------

5ffb194 add contao.image.resizer to studio locator
45815c6 add createIfDeferred method to ImageResult
9c02354 adjust ContaoCoreExtensionTest
71ffe3f also scan for 'srcset' elements (+ remove duplicates)
b73ba71 do not throw exception if there are no deferred images
4f30e2f simplify getting candidates + remove duplicate check
6f0b976 CS
412ce3e Merge branch 'master' into feature/studio-create-if-deferred
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this issue Apr 6, 2021
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Closes contao#2322
| Docs PR or issue | Todo

This adds the ability to synchronously trigger the creation of resized images from within an `ImageResult`. This is similar to `File#createIfDeferred()` but processes all resources (picture img + picture sources) instead of a single file.

Contrary to the method in `File` an exception will be thrown if the `contao.image.resizer` service does not support deferred resizing (`DeferredResizerInterface`) and exceptions won't be swallowed.

**Demo Usage:**
```php
$figure = $studio->createFigureBuilder()
    ->fromPath('files/public/foo.jpg')
    ->setSize('_my_size')
    ->build();

$figure->getImage()->createIfDeferred();

// It's now safe to access any of the generated image files directly
$pdf->addImage($figure);
```

Commits
-------

5ffb194 add contao.image.resizer to studio locator
45815c6 add createIfDeferred method to ImageResult
9c02354 adjust ContaoCoreExtensionTest
71ffe3f also scan for 'srcset' elements (+ remove duplicates)
b73ba71 do not throw exception if there are no deferred images
4f30e2f simplify getting candidates + remove duplicate check
6f0b976 CS
412ce3e Merge branch 'master' into feature/studio-create-if-deferred
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants