No Code Attached Yet
avatar brianteeman
brianteeman
14 Apr 2024

Steps to reproduce the issue

Add some png and jpg images to the /images folder

Go to the Filesystem local plugin and enable cache
image

Compare the file sizes in /images and /media/cache/com_media/thumbs

Expected result

ALL the files in the cache have been reduced in both dimension and filesize

Actual result

All the file dimensions have been reduced but the filesize has in some cases increased

System information (as much as possible)

I have prepared a zip containing 5 images so that we can compare with the same image

filename original filesize kb cache filesize kb reduced
image1.png 44.05 105.85
image2.png 452.83 75.3 ✔️
image3.png 30.47 93.39
image4.jpg 250.94 27.79 ✔️
image5.jpg 114.55 26 ✔️
image6.jpg 260.38 34.84 ✔️

Test Images

test.zip

Comments

I appreciate that the original images might have been saved with different compression algorithms and ratios. These are just a random selection of images on my hdd.

In all cases the file has been reduced in dimensions so at the very least it would be reasonable to assume that its a bug if the reduced file is double the storage size of the original

avatar brianteeman brianteeman - open - 14 Apr 2024
avatar joomla-cms-bot joomla-cms-bot - change - 14 Apr 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Apr 2024
avatar Fedik
Fedik - comment - 14 Apr 2024

It kind of expected, for PNG.
It not a bug.
I would say: it is how algorithm work for PNG.

In theory we can try to play with higher compression, but still, in some cases PNG can be bigger.

avatar brianteeman
brianteeman - comment - 14 Apr 2024

How can it be expected to reduce the dimensions of a png and yet the filesize increases by 300%

That completely defeats the objective of the thumbnail creation

/me doesnt understand how it is not a bug - please can you explain

avatar Fedik
Fedik - comment - 14 Apr 2024

It is PHP side (PHP GD), not Joomla.
All we can do is try to set "quality" https://www.php.net/manual/en/function.imagepng.php different from default.

How can it be expected to reduce the dimensions of a png and yet the filesize increases by 300%

Depend from amount of detail the image have, it can happen for PNG in any application, not only PHP

avatar brianteeman
brianteeman - comment - 14 Apr 2024

As the purpose of creating the thumbnail is to crerate a fast loading version of the image and this thumbnail will only be displayed in the media manager why not always set the compression to the maximum.

Otherwise any png that has been optimised before uploading to joomla will generate a larger file when resized

avatar brianteeman
brianteeman - comment - 14 Apr 2024

The code exists already to select the image quality. Its just not used at all so the compression defaults to 0 :(

avatar Fedik
Fedik - comment - 14 Apr 2024

It a bit tricky, PNG have a range -1 ... 9, JPG -1 .. 100.
Need an extra logic, extra code, but should be possible.
Someone can try.

I just can't say how much it will really help. For cases when User upload "optimised PNG", the thumbnail still may be bigger after PHP processing.

As the purpose of creating the thumbnail is to crerate a fast loading version of the image

Well, it is more for really large (resolution) images , for images with small resolutions it probably irrelevant

avatar brianteeman
brianteeman - comment - 14 Apr 2024

I did a quick manual try with PNG set to 9 and the difference was amazing.

Our code supports different settings for jpg and png compression/quality it's just not being used for the thumbs

avatar dgrammatiko
dgrammatiko - comment - 15 Apr 2024

@brianteeman although the Image class supports different compression ratios the functionality for the thumbnails doesn't expose it:

$image->createThumbnails([$this->thumbnailSize[0] . 'x' . $this->thumbnailSize[1]], $image::SCALE_INSIDE, dirname($thumbnailPath), true);

public function createThumbnails($thumbSizes, $creationMethod = self::SCALE_INSIDE, $thumbsFolder = null, $useOriginalName = false)

I did the implementation for the thumbnails so I guess this is my fault, if you need to blame somebody

avatar brianteeman
brianteeman - comment - 15 Apr 2024

not interested in blame - just interested in making the thumbs functionality work as intended. I am certain you didnt intent to make the thumbnails bigger than the original ;)

avatar dgrammatiko
dgrammatiko - comment - 15 Apr 2024

If you still have the test site available could you try adding:

$image->setThumbnailGenerate(false);

after: https://github.com/joomla/joomla-cms/blob/45adb61f8306b945f43b4326305fafe87c154aa2/plugins/filesystem/local/src/Adapter/LocalAdapter.php#L952C9-L952C35

Should do the trick

avatar brianteeman
brianteeman - comment - 15 Apr 2024

surely that just disabled the creation of thumbnails ??

avatar dgrammatiko
dgrammatiko - comment - 15 Apr 2024

surely that just disabled the creation of thumbnails ??

The docs say that this controls the quality:

/**
* Method for set option of generate thumbnail method
*
* @param boolean $quality True for best quality. False for best speed.
*
* @return void
*
* @since 3.7.0
*/
public function setThumbnailGenerate($quality = true)

avatar brianteeman
brianteeman - comment - 15 Apr 2024

my bad - i will test that soon

avatar brianteeman
brianteeman - comment - 15 Apr 2024

all that does is to create reall bad quality thumbnails that are the same filesize as the good ones

filename original filesize kb cache filesize kb cache filesize after
image1.png 44.05 105.85 1-5.85
image2.png 452.83 75.3 75.3
image3.png 30.47 93.39 93.39
image4.jpg 250.94 27.79 31.34
image5.jpg 114.55 26 30.48
image6.jpg 260.38 34.84 42.02
avatar dgrammatiko
dgrammatiko - comment - 15 Apr 2024
avatar alikon alikon - close - 15 Apr 2024
avatar alikon
alikon - comment - 15 Apr 2024

please test #43282

avatar alikon alikon - change - 15 Apr 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-04-15 17:04:07
Closed_By alikon
avatar impressionestudio
impressionestudio - comment - 16 Oct 2024

My concern while testing this feature was whether Joomla would keep thumbnails of non-existent images inside the "media/cache/com_media/thumbs/images" folder. So I thought clearing the cache via System > Clear Cache is a good way to clear all the thumbnails, so they reproduce again when I visit Media Manager. Unfortunately it seems it doesn't. Even if I disable this feature in the "FileSystem - Local" plugin, they remain there.
a) Shouldn't Clear Cache clear the thumbnails?
b) Shouldn't disabling this feature via the "FileSystem - Local" extension also delete these thumbnails, regardless of Clear Cache?

avatar fgsw
fgsw - comment - 16 Oct 2024

@impressionestudio Can you open a new Issue for your comment and link also to this Issue? Comments on closed issues or pull request get less attention.

avatar dgrammatiko
dgrammatiko - comment - 16 Oct 2024

The clearing of cache should be implemented but I don’t like the idea of automatically removing the cache if the option is disabled…

Add a Comment

Login with GitHub to post a comment