Thumbnail quality hard coded in core's FileVersion->rescanThumbnails

Permalink
I wanted to use the new Thumbnail functionality (with Thumbnail Types) in the new 5.7, but I cannot set the quality anywhere. After some investigating, I found that the quality was hardcoded as '60' in FileVersion->rescanThumbnails.

Unfortunately 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...

 
exchangecore replied on at Permalink Reply
exchangecore
First of all can you provide some more context (code sample woudl be great) on how you're using the image helper that the setJpegCompression($level) doesn't work? The function definitely exists and should still work as far as I know (https://github.com/concrete5/concrete5-5.7.0/blob/f41a03ca8e136d4619... ).

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... )
sandsoft replied on at Permalink Reply
I'm using ImageHelper as follows:

$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...
exchangecore replied on at Permalink Reply
exchangecore
You're right on that, it is hard coded on the rescan and that should probably be changed out to use the newly available default setting. (New as of version 5.7.4). On the other hand, the rescan only happens when you duplicate a file, or when you import files I think. So that's not the issue.

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.
sandsoft replied on at Permalink Reply
Thank you for your answers so far...

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()...
exchangecore replied on at Permalink Reply
exchangecore
Files should be created automatically if they don't exist and they will be placed into cache. If it's not getting created automatically you've got other issues. The answer shouldn't be to rescanThumbnails but instead to figure out why it's not creating them if they don't exist (application/files/cache directory permissions maybe?) You also might start by simply replacing your getThumbnail function with the latest one in the core. It doesn't look like that function leverages any new features but it may fix some stuff.

https://github.com/concrete5/concrete5-5.7.0/blob/develop/web/concre...
sandsoft replied on at Permalink Reply
Files are created perfectly when using the ImageHelper, just not when using the following method:

$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.
exchangecore replied on at Permalink Best Answer Reply
exchangecore
I wouldn't rescan on get, that's seriously inefficient. Once the thumbnail type is added it should create the thumbnail when the image is uploaded. I'm not sure how it works for images that already existed, you might have to manually regenerate those using the file manager's Bulk actions to rescan the images that already existed i'm not sure though it might happen automatically.

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;
sandsoft replied on at Permalink Reply
Well, I would probably do it like this:
$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)
sandsoft replied on at Permalink Reply
Just found out that the rescanThumbnails() has been modified in the develop branch, just after this discussion. Same for the ImageHelper.

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...
exchangecore replied on at Permalink Reply
exchangecore
If it's in the develop branch they will be in the next release of Concrete5.