Feature suggestion: optimizing thumbnails

Discussion corner for Developers of Serendipity.
Post Reply
Manko10
Regular
Posts: 50
Joined: Sun Dec 26, 2010 4:58 pm

Feature suggestion: optimizing thumbnails

Post by Manko10 »

Hi there,

I'm using pngquant (http://pngquant.org/) for some of my images to reduce them to 8-bit of color depth which is often more than enough. pngquant does a very good job at compressing my images (especially illustration artwork and screenshots, not so good on real photos). Even fake alpha transparency is often retained, so often you can't tell which one is the optimized version and which one the original if you don't look at the file size.
However, when I upload them to Serendipity and generate thumbnails from them, these are again full-blown 32-bit PNGs (or at least 24-bit) resulting in a file size often larger than the original image.

My suggestion would be to check the avilability of pngquant and use it to optimize thumbnails which are generated from 8-bit source files, so they keep their optimization.
32-bit and 24-bit PNG thumbnails could also be optimized with a tool for lossless optimization such as pngrewrite, pngout or pngcrush.
Similar optimizations could be done for JPEGs with jpegoptim.

What do you think?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Feature suggestion: optimizing thumbnails

Post by garvinhicking »

Hi!

I think the performance penalties of checking for pngquant should not be too hard, since the process is only called when optimizing images.

So yes, I think we could implement such a patch. Do you want to issue a Git pull request and provide a patch?

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Manko10
Regular
Posts: 50
Joined: Sun Dec 26, 2010 4:58 pm

Re: Feature suggestion: optimizing thumbnails

Post by Manko10 »

I guess I can do that. Although I haven't been too much into the s9y code.
Manko10
Regular
Posts: 50
Joined: Sun Dec 26, 2010 4:58 pm

Re: Feature suggestion: optimizing thumbnails

Post by Manko10 »

BTW In order to be able to determine the color-depth of the image file I have to use some third-party function like this: https://github.com/ktomk/Miscellaneous/ ... geinfo.php
It is a libary for inspecting PNG files for things like color depth, color type etc. It consists of 54 lines of code (including comments and white space). Do you think it would be okay to include this function into the s9y core?
I guess the licenses should be compatible (s9y: BSD, lib: Apache 2.0)
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Feature suggestion: optimizing thumbnails

Post by yellowled »

Manko10 wrote:Similar optimizations could be done for JPEGs with jpegoptim.
Or jpegtran.

YL
Manko10
Regular
Posts: 50
Joined: Sun Dec 26, 2010 4:58 pm

Re: Feature suggestion: optimizing thumbnails

Post by Manko10 »

I just wanted to start writing the patch, but I'm not so sure what the best way is to determine the paths of pnquant, pncrush and jpegoptim. I could just issue the commands, but, I'm hesitating to do that because I can't know which command I really call. It could also do something else if the user wrote a shell script with that name, e.g.
Just using executables in /usr/bin/ is also not a great way because such tools hardly ever exist in /usr/bin. Most often they are somewhere in the user's home directory.
The only good option I see is adding an option to the backend:

Code: Select all

[✓] Optimize thumbnails?
    Path to pngquant: [foo]
    Path to pncrush: [bar]
    Path to jpegoptim: [baz]
Do you think, there's a better way to do this?
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Feature suggestion: optimizing thumbnails

Post by yellowled »

Manko10 wrote:Most often they are somewhere in the user's home directory.
But if they are, the user should set his $PATH properly to include them.

I'm wondering how many users actually have these installed on a webserver …

YL
Manko10
Regular
Posts: 50
Joined: Sun Dec 26, 2010 4:58 pm

Re: Feature suggestion: optimizing thumbnails

Post by Manko10 »

This will hardly be pre-installed on any server, but if it's a feature of s9y, the user is free to install it on his webspace.
But if they are, the user should set his $PATH properly to include them.
Of course, but perhaps he did, not knowing that s9y uses the same command. But if we let the user choose the file name we can be pretty sure that he knows about this.
Another advantage would be that also users who can't modify the PATH variable can use this feature because they only need to have the binaries in some arbitrary place on their webspace.
Post Reply