LiipImagineBundle icon indicating copy to clipboard operation
LiipImagineBundle copied to clipboard

Question: is there possibility to retrieve source image without processing it?

Open jkabat opened this issue 6 years ago • 7 comments

I tried to search for answer but failed to find one.

Sometimes you need to grab source image without touching it and if I use |imagine_filter in twig, I always end up by getting processed file, even if you do not set any filter at all.

Is there some option I'm missing (quality = 100%, or similar)? Or the only way is to create custom filter which will basically copy the source to target?

jkabat avatar Jan 07 '19 17:01 jkabat

It will always cache a new copy of the file (using the original file as its source), but it will not apply any transformations or post-processors to the file, assuming you have defined an empty filter-set and post-processor configuration entry.

In this situation, while it is a new file, the only operations that are performed with an empty filter-set/post-processor configuration are:

  1. There is a check for a matching cache file, which is returned if one is found that is not stale; otherwise, if no cache file exists or if the existing cache file is stale, the process continues at the next step.
  2. The image data is read into a concrete ImageInterface instance using the imagine-library API (which internally uses the configured image manipulation library; one of gd, imagick, or gmagick).
  3. The image data from the prior created ImageInterface instance is written out to a cache file.
  4. The saved cache file is then served as the image resource for all matching requests.

Nothing else is performed. Have you checked your full configuration by dumping the bundle's config using the Symfony console to ensure there are no other options that could be effecting output?

The architecture of this bundle currently requires an intermediate cache file, so I do not believe you can completely remove this functionality, as you requested to do in your question.

If the cache file is substantially different from the original input file, there must be something occuring within the external imagine-library; as far as I understand, this bundle does not introduce any changes in this situation. I would look into how that external library behaves and any options it may apply itself.

robfrawley avatar Jan 07 '19 20:01 robfrawley

As I understand it. Steps 2 and 3 always manipulate the original file data through Imagine (open, save), because Imagine always opens the resource (using gd, imagick or gmagick) and saves it to desired path (which always changes the file data).

Would it be possible to add filter parameter to LiipImagineBundle (for example passthrough: true) that would skip the steps 2 and 3. and instead just copy the original file to cache?

dmagician avatar Jan 08 '19 09:01 dmagician

@robfrawley thanks for your comprehensive answer. So there might be some defaults which are used by imagine library and which are causing degradation (or manipulation) of the output.

What would you suggest if I'd like in certain cases (let's say for filter_set named "original") skip opening source by configured driver. I do not know architecture of the bundle that's why I'm asking - would be possible to eg: change configured driver to custom "dummy" one dynamically?

The point is to use cache for these "original" files the same way as it is done for all other filter_sets.

jkabat avatar Jan 08 '19 15:01 jkabat

I am also experiencing related issues by filtering gif images. The output cache resolved image increases the original size even without performing any filter or post-processor operations.

Because we have images with different mime types, we wanted to apply certain filter_sets to the images skipping the gif ones. We tried with empty filter_sets and runtime options, also with quality of 100, but something occurs while saving the new image binary that increases significantly the size.

Is there any workaround to achieve this? One solution could be to check the image mime type and only apply the filter_set if matches desired extensions by it seems a bit ugly way.

guillermogfer avatar Nov 26 '20 12:11 guillermogfer

i am cleaning up old issues. if this is still relevant and keeps happening with the latest version of the bundle, please reopen the issue.

dbu avatar Oct 06 '21 07:10 dbu

@dbu I do not have access to reopen, but Im still interesting in solution if anybody will take a shot on this one.

jkabat avatar Oct 19 '21 08:10 jkabat

i reopened the issue. can you propose a solution @jkabat how this should be handled?

dbu avatar Oct 19 '21 08:10 dbu