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 FormatExtensionResolver #1300

Merged
merged 2 commits into from
Oct 5, 2021
Merged

Conversation

ossinkine
Copy link
Contributor

Q A
Branch? 2.0 (was branched from master)
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1198
License MIT
Doc PR

I've added a new resolver to resolve issue with file extension when filter changes image format, see related issues.
Just add it as decorator to your primary resolver and images will be stored with proper extensions:

services:
    acme.imagine.cache.resolver.format_extension:
        class: Liip\ImagineBundle\Imagine\Cache\Resolver\FormatExtensionResolver
        arguments:
            - "@liip_imagine.cache.resolver.default"
            - "@liip_imagine.filter.configuration"
        tags:
            - { name: "liip_imagine.cache.resolver", resolver: "format_extension" }

@coveralls
Copy link

coveralls commented Sep 21, 2020

Coverage Status

Coverage increased (+0.1%) to 83.776% when pulling 97b579c on ossinkine:format-extension-resolver into 469b178 on liip:2.x.

@robfrawley robfrawley self-requested a review September 30, 2020 15:40
@robfrawley robfrawley linked an issue Sep 30, 2020 that may be closed by this pull request
@robfrawley robfrawley added State: Reviewing This item is being reviewed to determine if it should be accepted. Level: New Feature 🆕 This item involves the introduction of new functionality. labels Sep 30, 2020
Copy link
Collaborator

@robfrawley robfrawley left a comment

Choose a reason for hiding this comment

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

Are you able to include documentation regarding this new feature? Our documentation source files are located under the Resources/doc project directory and can be locally built using the build guide from the project Wiki to confirm your documentation changes and/or additions properly compile and render as expected. If you have no familiarity with reStructuredText (RST) (which is the markup language used for our docs) or you do not have the time or ability to update the docs for this feature, please advise and I will look into doing so myself prior to merging this PR.

@ossinkine ossinkine force-pushed the format-extension-resolver branch from e8a0461 to 2661691 Compare October 12, 2020 19:10
@ossinkine
Copy link
Contributor Author

@robfrawley I've added the documentation for this feature but unfortunatelly I was not able to build the doc according to build manual. Feel free to fix it if something is wrong.

@Perni1984
Copy link

@ossinkine many thanks for this!

@ossinkine ossinkine force-pushed the format-extension-resolver branch from 0db3231 to 3e81efb Compare October 30, 2020 16:43
@ossinkine
Copy link
Contributor Author

@dbu Thank you for fixes 👍

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

looks good to me. okay to merge, @robfrawley ?

@lsmith77 lsmith77 changed the base branch from master to 2.x January 5, 2021 12:50
@ossinkine ossinkine closed this Jan 15, 2021
@ossinkine ossinkine deleted the format-extension-resolver branch January 15, 2021 13:02
@acrobat
Copy link

acrobat commented Jan 17, 2021

@ossinkine why did you close this PR?

@ossinkine ossinkine restored the format-extension-resolver branch January 18, 2021 09:08
@ossinkine
Copy link
Contributor Author

Looks like I accidentally deleted the branch while creating another PR.

@ossinkine ossinkine reopened this Jan 18, 2021
@ossinkine ossinkine force-pushed the format-extension-resolver branch from 3e81efb to 678fab7 Compare January 18, 2021 09:16
@ossinkine ossinkine force-pushed the format-extension-resolver branch from 678fab7 to 97b579c Compare January 18, 2021 09:39
@tarjei
Copy link

tarjei commented Feb 1, 2021

Hi, any news on this PR? heic files are becoming an issue so this is needed more an more.

@plandolt
Copy link
Contributor

plandolt commented Apr 7, 2021

Looking forward to this resolver. Is there anything to add/help?

Another question is about a possible conflict when change the format on two or more files with the same filename except a different extension. e.g. 1.jpg and 2.png transformed to webp format will both result in 1.webp. But those file could be totally different. Should the extension instead of being replaced better being added? Or should this behaviour be configurable?

Plus: This one does not solve the problem of no redirect on the first request in which the cached version will be generated.

@ossinkine
Copy link
Contributor Author

@scuben I have no idea why this PR still is not merged, so I don't how you can help 🤷‍♂️

What about file extensions, I though about that and it seemed to me that filenames like 1.jpg.webp are ugly enough. We are using hash names to avoid conflicts.

@trsteel88
Copy link
Contributor

@lsmith77 are you able to merge this branch if it is fine? I'm looking to implement webp image formats (by defining format: webp) on additional filtersets and it doesn't alter the path name :(

@trsteel88
Copy link
Contributor

Actually just looking at this code. It doesn't look like this is just something you can turn on. You would need to implement it in your services each time. Would it be better to have this as an option? Or alternatively, always replace (or append) the new extension?

@ossinkine
Copy link
Contributor Author

@trsteel88 We can't always change the extension because it breaks BC. The such functionality in this library extends by decorating cache resolvers. Why do you think the adding an option is better then adding the decorator service?

@lsmith77 Indeed, what is keeping us from merging?

@lsmith77
Copy link
Contributor

lsmith77 commented Jun 7, 2021

the main issue is time reviewing ..

@fbourigault do you have time to look into this PR?

@robfrawley
Copy link
Collaborator

@lsmith77 I can actually take a look at this later this week if no one else gets around to it.

@robfrawley robfrawley self-requested a review June 8, 2021 04:06
@trsteel88
Copy link
Contributor

trsteel88 commented Jun 8, 2021

@trsteel88 We can't always change the extension because it breaks BC. The such functionality in this library extends by decorating cache resolvers. Why do you think the adding an option is better then adding the decorator service?

Make it an option would mean BC would still be respected.

e.g. "redirect_format_extension" = false by default.

Then on any new installs, we could just specify true to make use of the automated redirect.

@trsteel88
Copy link
Contributor

Not sure if this is a big deal, but the getBrowserPath() does not render the correct extension before the image is stored.

This means that the path will render as media/cache/resolve/foo/bar.jpg if the image does not exist yet. Then it will redirect to media/cache/foo/bar.webp

After the file is generated, it will then render as media/cache/foo/bar.webp which is correct.

@dbu
Copy link
Member

dbu commented Oct 5, 2021

thanks! and sorry for the delay.

i think for version 3 we should make this the default behaviour - it seems weird to not always do it. (also, with content negotiation for webp and stuff, did we currently only store one version, or does that take care of the extension?)

@dbu dbu merged commit 7f9d50b into liip:2.x Oct 5, 2021
@dbu dbu mentioned this pull request Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Level: New Feature 🆕 This item involves the introduction of new functionality. State: Reviewing This item is being reviewed to determine if it should be accepted.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formats and extensions
10 participants