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

Add a createIfDeferred() method to the ImageResult class #2368

Merged
merged 8 commits into from Oct 14, 2020

Conversation

m-vo
Copy link
Member

@m-vo m-vo commented Sep 27, 2020

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:

$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);

@leofeyer leofeyer added this to the 4.11 milestone Sep 28, 2020
ausi
ausi previously approved these changes Sep 28, 2020
return;
}

$resizer = $this->resizer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check this first? If the resizer isn't available, we don't need to collect any $deferredImages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leofeyer
leofeyer previously approved these changes Oct 9, 2020
@leofeyer leofeyer requested a review from ausi October 9, 2020 15:20
@leofeyer leofeyer merged commit 5646b82 into contao:master Oct 14, 2020
@leofeyer
Copy link
Member

Thank you @m-vo.

@m-vo m-vo deleted the feature/studio-create-if-deferred branch January 2, 2021 12:03
@leofeyer leofeyer changed the title Add createIfDeferred to ImageResult Add a createIfDeferred() method to the ImageResult class Jan 18, 2021
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this pull request 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding createIfDeferred to ImageResult
4 participants