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

Bad Url when using "format" #98

Closed
rdohms opened this issue Aug 16, 2012 · 9 comments
Closed

Bad Url when using "format" #98

rdohms opened this issue Aug 16, 2012 · 9 comments
Labels
Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.

Comments

@rdohms
Copy link

rdohms commented Aug 16, 2012

I'm still trying to figure out the details on this one. But here is the scenario:

  1. My profile uses "format: jpg"
  2. I upload a png image
  3. I get a broken image and when inspecting that i get that it failed to "find source image"

So i looked into this.

  1. My template passes /url/to/image.png which is a real file and a real and valid url
  2. Twig function generates a url: cache/path/to/image.jpg (this would be the image that should be generated)
  3. Inspecting the filterAction, it never gets the original name with png so it never manages to generate a cache file

If i forcefully switch the url to png it runs, caches and no longer has any problems.

It seems to me like this force switch of extensions is making the bundle lose the reference to the original and what cache file it should generate. Any ideas on this?

@pgouv
Copy link

pgouv commented Sep 21, 2012

This happens because template changes the extension and then it cant locale it. But this was done in order to fix the case like having a jpeg image with .png extension. The easiest workaround is to specify
formats : ['jpg','png',...whatever]

Then there is code that does file exists at all these extensions.Another workaround might be to provide as query parameter the real extension in order for it to know what to search but this needs code modification

@WishCow
Copy link

WishCow commented Mar 11, 2013

+1, I also encountered this.

@sgarner
Copy link

sgarner commented May 7, 2013

This problem still exists. Has anyone solved it yet?

@pgouv
Copy link

pgouv commented May 7, 2013

sgarner i posted a workaround for this (1 minute workaround)

@sgarner
Copy link

sgarner commented May 7, 2013

You mean the formats : ['jpg','png',...whatever] thing?

That doesn't make any difference, as far as I can tell.

@pgouv
Copy link

pgouv commented May 7, 2013

for me it solved the problem. It needs an array of formats to look.

@sgarner
Copy link

sgarner commented May 7, 2013

I have liip_imagine.formats set to [jpeg, png, gif]. My filter has format: jpeg, because I want all images for this purpose to be converted to JPEGs.

I am storing images using Gaufrette. If I upload a PNG, the source image is stored in PNG format with a key like "516dc718e76d0216271819.png". This key is the path that gets passed to the twig imagine_filter. Here is what happens:

  1. During execution the \Liip\ImagineBundle\Imagine\Cache\CacheManager::generateUrl method notices that the format is set to JPEG and so it 'corrects' the file extension, rewriting the key as "516dc718e76d0216271819.jpeg".
  2. In a dev environment the URL to the image which is then written into the page looks like /app_dev.php/media/cache/filter_name/516dc718e76d0216271819.jpeg.
  3. When a request is received to this URL, it doesn't know what to do with it because 516dc718e76d0216271819.jpeg doesn't exist yet, so a "Source image not found" exception is thrown.
  4. If one manually initiates a request to the source key at /app_dev.php/media/cache/filter_name/516dc718e76d0216271819.png, then the JPEG version will be created.
  5. A subsequent request to the same URL will redirect to the static file /media/cache/filter_name/516dc718e76d0216271819.jpeg, as will a request to the previously generated URL /app_dev.php/media/cache/filter_name/516dc718e76d0216271819.jpeg.

@rdohms
Copy link
Author

rdohms commented Sep 9, 2013

BTW, the workaround only works for the FileSystemResolver, if you are using the StreamResolver then this scenario is simply impossible to get around, see #231

@havvg
Copy link
Contributor

havvg commented Jan 28, 2014

see #93

@havvg havvg closed this as completed Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.
Projects
None yet
Development

No branches or pull requests

5 participants