ImageMagick Thumbnailer

Couple of suggestions - ImageMagick Thumbnailer

Couple of suggestions

by thecoalman » Tue Sep 10, 2019 9:18 am

I have been working on implementing this on my own forum for all uploaded files and your extension set me off on the right path so thanks for that. ;) Here is a few things I'm doing.

For privacy purposes and to shave off a few KB you can remove just the EXIF information after processing the image for orientation. IPTC, ICC color profiles etc will be preserved. Of course the uploaded full sized image would still have the EXIF information so the only usefulness for the thumbnails is file size reduction.

Code: Select all

removeImageProfile('exif');
This removes all meta data for even smaller file size but from what I'm reading this is bad idea because it strips the color profile and can lead to poor rendering of the image.

Code: Select all

stripImage();
As a side note if you just want to remove the EXIF or other meta data without resizing/re-sampling if you use setCompressionQuality(100); to write the file it appears there is no re-sampling.

From what I'm reading setCompressionQuality() has no affect on PNG. You can use the following for compressing PNG, it doesn't save much but it's better than nothing. It's slow on the execution side.

Code: Select all

setOption('png:compression-level', 9);
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3491
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Couple of suggestions

by canonknipser » Tue Sep 10, 2019 3:42 pm

Thanks for your suggestions.

Currently, I don't plan to suppress exif data (it would make my other extension View exif data worthless :oops: ) - and just for saving a few byte It is not worth to implement it only on thumbnails.
But it may go into a extension-in-developing (Server-Side resizing using Imagick library) as a per-forum setting or per-upload setting.

Thanks for the hint with png compression, maybe I add it, but as you mentioned, it can be a very slow process, so eventually it's not worth it for thumbnail. I'll need to verify that

Thanks also for the hint with SetCompressionQuality(100);, but as far as I know, Imagick always resample the images on rewrite, because they are decompressed into the buffer as a bitmap, and creating jpg is a lossy process. See the hints in bold: https://imagemagick.org/Usage/formats/#jpg
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Couple of suggestions

by thecoalman » Tue Sep 10, 2019 8:59 pm

canonknipser wrote:- and just for saving a few byte It is not worth to implement it only on thumbnails.
But it may go into a extension-in-developing (Server-Side resizing using Imagick library) as a per-forum setting or per-upload setting.
That's where I'm using it, I'm also converting png to jpg. Didn't get to it yet but I need to add a check box for "do not convert to jpg" for line drawings graphs etc. Anybody else reading this before you ask no I won't be making an extension, sorry I don't have the time.
Thanks for the hint with png compression, maybe I add it, but as you mentioned, it can be a very slow process, so eventually it's not worth it for thumbnail. I'll need to verify that
You may only get a 10% reduction but as far as I'm concerned every byte counts. Other than an increase in the process time there is no downside to not doing it.
Thanks also for the hint with SetCompressionQuality(100);, but as far as I know, Imagick always resample the images on rewrite, because they are decompressed into the buffer as a bitmap, and creating jpg is a lossy process. See the hints in bold: https://imagemagick.org/Usage/formats/#jpg
Perhaps I'm misinterpreting the results but every image I have ran through this process is a few KB's smaller except for one really large image from a Canon DSLR which was a few KB larger after processing, online image checkers show no difference. Perhaps you have some better tools for this comparison since you are a photographer. I attached before and after.
Attachments
after.jpg
before.JPG
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3491
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Couple of suggestions

by canonknipser » Wed Sep 11, 2019 3:26 pm

Every "save file" for jpeg images changes the quality and you loose details (the lossless compression was defined for the jpeg2000 standard, but that file format was "dead on arrival").

You may not see compression artefacts in "normal images", but in high quality images with a lot of details. No offence, but you attached image is not a good example for a lot of details :oops:
See also the link I provided some posts earlier:
Normally this lossy nature of JPEG data is not very noticeable. However it can become noticeable when you either load and save a JPEG image multiple times or use a very low quality with a diagram showing sharp color changes.
However as long as you don't load or re-use JPEG images over and over (preserve and apply operations from the original source), it is still a good file format even image types it is not particularly good at handling.
For reading/removing/manipulation exif and other meta information offline I prefer a tool called exiftool, which is a set of perl scripts (a win and mac wrapper interface is also provided by the author and/ or friends of exiftool). This tool doesn't (in most cases) touch the image data with the file, it just reads and writes the meta data.
But, being a perl script, is not as easy to include in a php application. Therefore I follow a project called pel (PHP Image Library), but it looks not ready yet.

So, whenever my new extension will be ready, the end user will have a chance to decide whether he will (during upload) remove exif data, resize images, rotate images ... because every function will result in loosing quality because of compression and I will give him hints to do those things beforehand on his local device because he has a lot more control than in a automated background process.


And again, thanks for the png hint, I opened a issue so that hint won't get lost
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Couple of suggestions

by thecoalman » Thu Sep 12, 2019 12:05 pm

canonknipser wrote:Every "save file" for jpeg images changes the quality and you loose details (
I'm not a photographer but I have some pretty extensive knowledge of the technical aspects of images, video and audio. In particular video, of course the same rules that apply to compressed video apply to images. As I often tell people that are editing or converting video as a general rule it's all down hill from the source.

Once again perhaps I'm misinterpreting the results but online image diff tools that are comparing the image data do not show any difference between those two images.

You may not see compression artefacts in "normal images",


I'm not visually comparing these, I used a diff tool for comparing images.

I went and redid it with better image. I'm still getting same results. file sizes are a few KB's smaller and oline diff tools show the images to be the same.
Attachments
after2.JPG
before2.JPG
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3491
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact: