Thumbnail quality hard coded in core's FileVersion->rescanThumbnails
PermalinkUnfortunately I need mostly qualities 80 and 35.
Then I tried using the old ImageHelper + setJpegCompression, but changing the compression does not seem to have any effect on the image generated (file size does not change). After examining the source for the ImageHelper in 5.7, I think it uses the new 5.7 image manipulation routines, again without any control over compression/quality (setJpegCompression does not work anymore).
So I'm out of luck I guess...
If anyone knows of a method to define my own quality (preferably the 5.7 way) I'll be happy to hear that...
Note to the Concrete Core team: Would it be possible to add "quality" as a value when defining Thumbnail Types through the Dashboard?
If there is no solution before the end of tomorrow, I am forced to go back to 5.6...
$imgHelper = Core::make('helper/image'); $cover = $c->getAttribute('album_cover'); $imgHelper->setJpegCompression(10); $image = $imgHelper->getThumbnail($cover, 800, 800, false); $path_cover = $image->src;
Doesn't matter if I use 10 or 100 for compression, resulting image stayed the same filesize.
I'm using C5 version 5.7.3.1 by the way...
I checked the source of rescanThumbnails() in github and there is a hardcoded 60 there...
The issue has been fixed in Concrete 5.7.4 I believe. If you want you can go make the following changes to your ImageHelper file and I think it will clear up the issue.
https://github.com/concrete5/concrete5-5.7.0/commit/1887aad74c21d207...
In this case it's OK to modify that file since those change will be made the next time you upgrade concrete5.
If I change the file manually, will I be able to use 35 AND 80 as quality settings? Large images will get 80, thumbnails will get 35 (at twice the width and height of the image size needed, after which I downsize them to 50%, gives sharper images on mobile and desktop)
But I prefer to use the new method, so I don't have sites breaking next year or so when the old ImageHelper gets removed...
Except with the new 5.7 method (not using ImageHelper) I ran into the problem that when adding a new ThumbnailType, thumbnails are not created for existing images. Thus I needed to call rescanThumbnails()...
https://github.com/concrete5/concrete5-5.7.0/blob/develop/web/concre...
$cover = $c->getAttribute('album_cover'); $tt_cover = Type::getByHandle('album_cover'); $fv_cover = $cover->getApprovedVersion(); $fv_cover->rescanThumbnails(); // is this needed? $path_cover = $fv_cover->getThumbnailURL($tt_cover);
which is the 5.7 way as far as I could figure out.
Regardless they'll all have the same compression (60 right now) because they're thumbnails and that's hardcoded. If you want to change the image compression you'll need to run the image through the image helper instead of simply getting the thumbnail url. Really this isn't that inefficient since it will create the image and cache it and is probably the best option if you really need to set the compression down lower.
Something like
$cover = $c->getAttribute('album_cover'); $path_cover = $imgHelper->setJpegCompression(30)->getThumbnail($cover, 800, 800, false)->src;
$fv_cover = $cover->getApprovedVersion(); $path_cover = $fv_cover->getThumbnailURL($tt_cover); if (!$path_cover) { $fv_cover->rescanThumbnails(); // is this needed? $path_cover = $fv_cover->getThumbnailURL($tt_cover); }
Except that it is a bit verbose, and I feel the rescan should actually be done inside getThumbnailURL.
Maybe I'll write a wrapper for now, around the ImageHelper, and update the wrapper to the 5.7 method later, when quality works for that again... (or I'll dive into github and update it that way)
Made a couple of quick changes to the ImageHelper locally and I'll be using that for now. Hope the changes make it into 5.7.4 and will get released soon...
Secondly, there is a new "Default" jpeg compression setting which you can override in your application's concrete config settings (https://github.com/concrete5/concrete5-5.7.0/blob/develop/web/concre... )