How much are images compressed by discourse?

(Jeremiah Schultz) #1

I’m assuming that whatever is done to uploaded images is fairly basic, although I could very well be completely wrong. Assuming I’m correct has anyone considered integrating an image optimization program into the Discourse install?

For Wordpress I use “EWWW Image Optimizer” which is the best that I’ve tried so far, and they also have a standalone ‘plugin’ that does not require Wordpress. It uses jpegtran, TinyJPG, JPEGmini, optipng, pngout, pngquant, TinyPNG, and gifsicle.
Of course there are other solutions that do the same thing, I have no idea which might be best to use with Discourse…

(Joffrey Jaffeux) #2

Hi @Jeremiah_Schultz,

of course we do optimise images : discourse/file_helper.rb at master · discourse/discourse · GitHub

The optimisation chosen is a tradeoff between quality, time/cpu needed to process and acceptable size.

You might want to read: Zopfli Optimization: Literally Free Bandwidth

(Jeremiah Schultz) #3

Thanks for the info. I don’t know why I didn’t think before to just upload an image uncompressed to see how it does. Which I just did with an animated GIF. Which apparently wasn’t compressed at all. Is there perhaps a way to change that? Or will I need to install another program to compress animated GIFs?

(Jeff Atwood) #4

Animated gifs are already compressed, and re impressing them is effectively video encoding, so a rather different task.

(Jeremiah Schultz) #5

@codinghorror Not sure what you mean by already compressed? I can take nearly any animated GIF that I make or download and run it through FileOptimizer, and the size is cut in half approximately. It uses:

(Stephen Chung) #6

@Jeremiah_Schultz The GIF standard already has LZ (aka ZIP) compression built-in, although it is a poor compression method for images. In other words, every GIF image is already compressed. Therefore, you have nothing to gain by further compressing it, unless you go lossy.

giflossy is a lossy compression method which loses details.

Whether to lose details of the images that users upload is a matter of debate. GIF’s are usually used for high-contrast, high-detail clipart, as well as animated cartoons. Therefore, passing them through a lossy compression will lose image quality.

(Jeremiah Schultz) #7

Hi there @schungx Not to sound rude but, I guess you didn’t notice that I posted a link to a LOSSY gif optimizer. I know what the word means thanks. :wink:

The below GIFs were identical until I compressed one of them. Recorded from 1080P video at 10FPS. I challenge you to tell me which one was compressed without checking the file size. One of them is 5,458KB the other is 10,640KB. I guess I’m just trying to suggest that lossy GIF compression would be a nice option to have. Although I suppose myself or anyone else could just setup a cron job to do this, although I personally wouldn’t know how to stop it from wasting time re-compressing files.


(Stephen Chung) #8

Well I was merely responding to your question. :point_up_2:

It depends on the type of image. The images you posted are basically photos. The animated GIF is essentially used to record a video clip. This is NOT how most of the world uses animated GIF’s, or GIF images in general.

Most of the GIF’s are smallish, line-art or simple clipart, and most animated GIF’s are things like spinning “loading” signs, jumping banners etc. These, especially when in low resolution, cares about the exact color of each pixel. A lossy compression will get noticed.