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

Generated image is 44 times heavier than original image #1104

Closed
Kocal opened this issue Jun 12, 2018 · 7 comments
Closed

Generated image is 44 times heavier than original image #1104

Kocal opened this issue Jun 12, 2018 · 7 comments

Comments

@Kocal
Copy link

Kocal commented Jun 12, 2018

Today at work, one of our web integrator tell us about a problem about very VERY VERY heavy images.

After manual testings, we found out that the problem comes from this bundle.

In our CMS, we can switch the use of imagine_filter Twig filter. When the filter is used, the generated images are way too heavy in comparison of their original images.

So since we were running a old version (1.5.3), we tried to update to 1.9, then to 2.0 but the problem is still here.

Preconditions

  1. LiipImagineBundle: 2.0.0 (66959e1)
  2. PHP 7.2.5-1
  3. GD: 2.2.4

This is an extract of our config file:

liip_imagine:
    controller:
        filter_runtime_action: Path\To\ImagineController:filterRuntimeAction
    resolvers:
        default:
            web_path:
                web_root: "%kernel.project_dir%/web"
    loaders:
        default:
            filesystem:
                data_root:
                  - "%kernel.project_dir%/web/"
                  - "%nfs_media_path%"
    filter_sets:
        cache: ~
        dynamic:
            filters:
        Sw1500:
            filters:
                relative_resize: { widen: 1500 }
        # ... 

Steps to reproduce

  1. Upload an PNG image (~287 kB) (1366 x ... px)
  2. Waits for Kraken optimization (~100 kB)
  3. Link this image with an article
  4. Configure the image filter(e.g.: Sw1500 will wide images to 1500 pixels)
  5. Save
  6. Go to front office
  7. The Twig filter generate the image with the selected filter
  8. Image is too heavy (~ 4.7 MB)

This is how we call the Twig filter:

{# Some refactoring to make this code much easier to read/understand #}
{% set imageFilename = '/media/original/' ~ article.articleMedias.0.media.filename %}
{% set imageFormat = article.[...] %} {# will be 'Sw1500' #}
{% set imageFormatOptions = ... %}

<img src="{{ imageFilename|imagine_filter(imageFormat, imageFormatOptions) }} />

This is the image that I will upload:
original_483

This is the same image, but after upload and Kraken optimization:
original_484

So at the final, the original image weight ~100 kB.

Expected result

  1. The generated image by LiipImagineBundle should not weight 44 times the size of the original image

Actual result

When our image is passing to filter Sw1500, the generated image is too much heavy:

original_485

We don't understand why this thing happens.
The original image has a width of 1366px. Upscaling it to 1500px can't make it soo heavy, right?


At the moment, we didn't try to change the driver (from GD to Imagemagick), or to change built-in processors...
We will try tomorrow and see if it's better.

... Maybe Kraken is doing some strange things to the image, I will disable it and see if it do something.

Thanks!

@Kocal
Copy link
Author

Kocal commented Jun 13, 2018

Well, I still have a ~4.7 MB image even if Kraken optimization is disabled.

We tried imagick. It's better but it's still heavy.
The generated image now weight ~433 KB, its ~4 times heavier than the original image...

@Kocal Kocal changed the title Generated images are too heavy Generated image is x44 heavier than original image Jun 13, 2018
@Kocal Kocal changed the title Generated image is x44 heavier than original image Generated image is x44 times heavier than original image Jun 13, 2018
@Kocal Kocal changed the title Generated image is x44 times heavier than original image Generated image is 44 times heavier than original image Jun 13, 2018
@Kocal
Copy link
Author

Kocal commented Jun 15, 2018

We also tried to setup mozjpeg post processor, but generated images are horrible to look and still heavier than original images...

Do someone of you @lsmith77 @makasim @robfrawley have an idea about this problem?

Many thanks.

@veloxy
Copy link

veloxy commented Jun 29, 2018

@Kocal Have you tried to resize that particular image in GD/Imagick without any libraries at all, purely in PHP? How does the result of that compare to what Liip has generated?

@chregu
Copy link
Member

chregu commented Jun 29, 2018

Have you tried pngquant Post processor? Maybe your original image was optimized with that. That would explain a 2-4 bigger new image. If you want to get the even more bytes squeezed out, use zopflipng (after pngquant), but that may be slow.

No idea about GD though.

@Kocal
Copy link
Author

Kocal commented Jun 29, 2018

@veloxy Oh good point! No we didn't, but I will check it out monday.

@chregu For now, the only post processor we tried was mozjpeg for JPEG files, but results were bad because of double-optimization (Kraken & Mozjpeg).
For PNG files we didn't do anything, aswell I will check it out monday, in hope that will improve things 🙂

@jlemale
Copy link

jlemale commented Dec 11, 2020

A "few" Mondays have passed, what did you finally do ?

@Kocal
Copy link
Author

Kocal commented Dec 11, 2020

Hi, I don't really remember well but we still use the bundle with the https://kraken.io/ API for the optimization. I don't know if we always have the problem.

@Kocal Kocal closed this as completed May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants