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

Replace data uri with actual image for default mosaic image #6435

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

jorrit
Copy link
Contributor

@jorrit jorrit commented Oct 1, 2020

Subject

One day I was trying to read the output of php bin/console debug:container --parameters and I noticed that the output was unreadable due to a very long variable. The culprit was sonata.admin.configuration.mosaic_background which contained about 22KB of base64 encoded PNG data as a data URI.

This image is used as the default card background when displaying items in mosaic mode. It seems to me that this is not the most efficient way of embedding an image and it can be replaced with an asset and served using {{ asset() }}, much like the logo image.

This PR makes this change while maintaining compatibility with data: URIs. The image added in this PR is the same as the original image in the data URI but optimized using tinypng.com, which reduced more than half the size.

I have left the isImageAvailable() logic in the Metadata class as it was, even though I think it can be improved.

I am targeting this branch, because it is a backwards compatible change.

Changelog

### Changed
- Default mosaic background is now a file instead of a data URI.

sonata_admin.getMosaicBackground() :
meta.image }}" alt="{{ meta.title }}" />
{% set metaImage = meta.isImageAvailable is defined and not meta.isImageAvailable ? sonata_admin.mosaicBackground : meta.image %}
{% if not (metaImage starts with 'data:') %}
Copy link
Member

Choose a reason for hiding this comment

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

Should we trigger a deprecation for the case metaImage starts with 'data:' and removing it in the next major ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see a problem of leaving support in, in case anyone wants to genuinely use data URI's.

Best would be to have asset() accept data URI's and process like absolute URLs by returning them as-is, but waiting before that change happens takes too long.

If you and more people think data URI's should be deprecated that is fine by me.

@VincentLanglet VincentLanglet requested a review from a team October 1, 2020 22:41
@VincentLanglet VincentLanglet requested a review from a team October 2, 2020 07:54
@VincentLanglet VincentLanglet merged commit 2b31512 into sonata-project:3.x Oct 2, 2020
@VincentLanglet
Copy link
Member

Thanks @jorrit

@jorrit
Copy link
Contributor Author

jorrit commented Oct 2, 2020

Thank you all for reviewing and committing my nitpicks!

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.

4 participants