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 support multiple image formats in pictures #53

Merged
merged 6 commits into from
Jul 4, 2019

Conversation

ausi
Copy link
Member

@ausi ausi commented Jul 4, 2019

This pull request adds the possibility to use mutiple image formats and convert them automatically.

Examples:

// Convert bitmap images to JPEG and GIFs to PNGs
->setFormats([
    'bmp' => ['jpg'],
    'gif' => ['png'],
])

// Convert JPEG and WEBP images to one another to save bandwith on modern browsers
->setFormats([
    'jpg' => ['webp', 'jpg'],
    'webp' => ['webp', 'jpg'],
])

Related: php-imagine/Imagine#718

@ausi ausi added the feature label Jul 4, 2019
@ausi ausi self-assigned this Jul 4, 2019
@ausi ausi requested a review from Toflar July 4, 2019 08:18
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

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

Awesome!

src/PictureGenerator.php Show resolved Hide resolved
src/Resizer.php Show resolved Hide resolved
@leofeyer
Copy link
Member

leofeyer commented Jul 4, 2019

What is the use case for this? I understand what the code does, but when would I typically need this?

@Toflar
Copy link
Member

Toflar commented Jul 4, 2019

The use case is that we'll be able to automatically generate e.g. webp images for jpeg sources eventually giving us the ability to get this:

<picture>
  <source type="image/webp" srcset="assets/images/pic.webp">
  <img src="assets/images/pic.jpg">
</picture>

In other words: it's a major performance feature as we can let the browser decide if it understands more modern image formats and if so, select this instead of the bigger (in bytes) one.

@Toflar
Copy link
Member

Toflar commented Jul 4, 2019

And it will then make SEO rating tools like PageSpeed and co. very, very happy.

@ausi ausi marked this pull request as ready for review July 4, 2019 12:54
@ausi ausi merged commit 0e3d32e into contao:master Jul 4, 2019
leofeyer pushed a commit to contao/contao that referenced this pull request Jul 5, 2019
Description
-----------

Depends on contao/image#53
Related: php-imagine/Imagine#718

As @Toflar pointed out in contao/image#53 (comment) this feature makes it possible to automatically generate WEBP images.

I didn’t add `webp` to the default `contao.image.valid_extensions` configuration because not all plattforms support it. If someone wants to use this feature they need to add `webp` to the valid extensions in their *config.yml*.

Commits
-------

1b6ec2a Add support for image format conversion
271a98a Show help message if WEBP is not enabled
c67f82f Use 1.0.0-beta3 version of contao/image
c094d19 Fix tests
4631a2b Fix PHPStan issues
7465bcc Add formats to predifined sizes configuration
f71cd1e Fix image and picture tests
f3866e3 Fix PHPStan issues
b9fe888 Fix PHPStan issues
efe0c65 Fix the coding style
61accc2 Don’t use JSON for the formats option
a6cf0a9 Fix the coding style
leofeyer pushed a commit to contao/core-bundle that referenced this pull request Jul 5, 2019
Description
-----------

Depends on contao/image#53
Related: php-imagine/Imagine#718

As @Toflar pointed out in contao/image#53 (comment) this feature makes it possible to automatically generate WEBP images.

I didn’t add `webp` to the default `contao.image.valid_extensions` configuration because not all plattforms support it. If someone wants to use this feature they need to add `webp` to the valid extensions in their *config.yml*.

Commits
-------

1b6ec2ac Add support for image format conversion
271a98af Show help message if WEBP is not enabled
c67f82fe Use 1.0.0-beta3 version of contao/image
c094d193 Fix tests
4631a2b0 Fix PHPStan issues
7465bcc3 Add formats to predifined sizes configuration
f71cd1e3 Fix image and picture tests
f3866e34 Fix PHPStan issues
b9fe8884 Fix PHPStan issues
efe0c653 Fix the coding style
61accc28 Don’t use JSON for the formats option
a6cf0a9a Fix the coding style
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.

None yet

3 participants