Laravel-medialibrary: Generated responsive images bigger than original size?!

Created on 31 Dec 2017  路  18Comments  路  Source: spatie/laravel-medialibrary

Hello, we've experienced this and we're not sure which layer it relates to, is it something with the package, with the server generation tools, or maybe something fixed though configuration; check screenshots first:
screenshot_2017-12-31_01_40_09
screenshot_2017-12-31_01_39_58

As you can see, some of the smaller images (dimensions) are actually bigger in (size), which is strange. The original dimensions is 1920 * 1080 with size of 964.8 KB.

Another question: why responsive generation generate same dimension as original 1920 * 1080 before in addition to all the smaller sizes, as per docs I though it starts at 70% ratio, right?

Any thoughts?

Most helpful comment

We've merged a commit in the v7 branch to solve this, for both the gd and imagick drivers.

All 18 comments

@brendt could you take a look at this?

Next year is fine 馃嵕

@Omranic before looking into this, do you think it would be possible to share the image? It'll make debugging easier.

@brendt Well, that's unexpected request 馃槀 but yeah, seems ok! 馃槒

Not sure if GitHub will upload with same quality/size or not, but here we go:
screenshot 2017-10-05 21 10 01

Just in case someone interested in that material, it's here: "Actions on Google: Conversation Design Tips" https://www.youtube.com/watch?v=MSUPVbbhIGA&t=5s 馃槣

I'm going to take a look at this starting next week.

If I can't reproduce it using own test images, there's still a chance your image will be able to reveal a problem.

Did some testing. Turns out the original image was very helpful, as many images don't have this problem.

These are the file sizes of the responsive variations of the original image, in order of width.

original_test

I tried out lots of other images, and can see this issue returning in PNG encoded files, with large areas of the same color. An example:

screen___medialibrary_original_395_246

This image (its large variant) produces these filesizes:

white_image

Encoding the source image as JPEG, and then running it through the media library shows these filesizes, which makes much more sense:

white_image_jpeg

I also tried another kind of image, with lots of the same colors in it:

screen_black___medialibrary_original_472_295

black_image

So that's that for my first observations. Going to look into the reason now. It probably has to do something with the optimisers ran on each responsive variation.

@willemvb helped reveal the underlying issue. We compared a manually downscaled image in photoshop to the generated image from the medialibrary with kaleidoscope:

screen shot 2018-01-10 at 08 45 34

The interesting part is the white background, which should not differ; but the medialibrary (actually an underlying package) will take that plain white background, and make lots of artifacts. Instead of one color, there's a subtle difference between #ffffff and #fefefe. I'll be looking into where exactly this "optimisation" happens later this week. It will probably be one of the image optimiser binaries, which we should give an extra parameter to.

Update: the problem happens when downscaling images if using gd. imagick seems to work just fine. I'm looking if there's a way to configure gd to fix the issue.

Addressing the underlying issue: https://github.com/thephpleague/glide/issues/218

Wow, I respect the efforts given to deep dive into the insights of that issue, kudos 馃憦

We've merged a commit in the v7 branch to solve this, for both the gd and imagick drivers.

Has this problem been resolved yet? Im using v7, xampp with gd bundled (2.1.0 compatible) and same problem
image

I also have the same problem. Tried gd and imagick.
Both very similar in file size.

Original size: 286 KB
Biggest responsive size: 352 KB

dell-attore-14

Are you using v7 of the media library? If so, please provide an the downscaled image with the larger size, and the original.

Yes, I'm using v7.

Original
dell-attore-14

Downsized
dell-attore-14___medialibrary_original_1338_892

As I expected: there are lots of artifacts generated by the underlying glide library..

screen shot 2019-02-20 at 14 01 06

The way we solved this issue was by adding extra optimizers to the generated responsive images. This however never solved the underlying problem. I'm afraid that because of the complexity of your image, this optimizer trick isn't good enough to mitigate the real issue.

Unfortunately, the real issue is in a package that's not our own: https://github.com/thephpleague/glide/issues/218

You could try and play around in your local project with optimizer settings, but I'm afraid that's the only help I can give at the moment 馃槙

I see. Thank you so much for your time. I'll definitely post here if I find a good solution 馃憤

Kinda unrelated question. But are the generated responsive images compressed through the various optimization tools? If not; What's a good way to do this?

They should be optimised, which was the "fix" for this issue: https://github.com/spatie/laravel-medialibrary/commit/d96ce0e22db7069abf335424be65ed0232c0d135

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brendt picture brendt  路  4Comments

intrepidws picture intrepidws  路  3Comments

drtheuns picture drtheuns  路  3Comments

swash13 picture swash13  路  3Comments

netanelwebninja picture netanelwebninja  路  3Comments