Images are still too big -- how to compress further?

Images that are uploaded from smartphones are commonly over 4MB in size (my max upload size is set to 5MB). I just took one of these images are dumped it into ImageOptim and the size dropped to under 800KB. I can’t tell the difference when viewing the pics.

Is there any way to have something like this done on my forum automagically?


4.2MB and compressed to 759KB without making quality suffer?

That’s impressive since even Google can’t even do that

It’s not impressive, but that’s besides the point. I’m simply asking if there’s a solution or some kind of work around. I tried lowering the allowable upload max image size, but then users can’t upload images from mobile devices at all (“your file is too big, yadda yadda”).

4MB image sizes are simply unnecessary.


I’m very interested as well!

I though though that images get resized/compressed after initial upload, so you can even allow e.g. 10MB uploads, but limit max image width/height dimensions in your Settings.

1 Like

There is some support for this @zogstrip can elaborate as he has time.


Hey @zogstrip have you had time to look into this?

There is definitely demand for further compression / pixel size limiting after upload.

Imho it should be allowed to upload big files but optimize / downsize them on the server after upload based on parameters from admin config.

Specifically for mobile uploads it would be beneficial to downsample them while keeping high quality / low compression (then to keep high res and compress photo with loss). Phone lenses are very low quality and even that there is high megapixel (usually it is just marketing) chip it doesn’t have any more pixel information than reasonably downsized photo.


Yes. For example, for our non-commercial community it tends to become vital. Every cent counts when no one is sponsoring… How much money we spend on the server, it mostly depend on how much space our current $20/mo DigitalOcean instance still have.

Exactly… from my experience fast access drives (15k SAS HDD or SSD) have always been biggest factor to server operating cost.

FYI: I recently re-worked our upload pipeline, which includes auto-converting large PNGs into (very) small JPEGs. You can fine tune the quality of the JPEGs with the “png to jpg quality” site setting.


The paint point here was very large uploaded PNGs which had absolutely no business being lossless PNGs, when they could be lossy JPGs at 1/5 or less the size. For small images (1280x720 or less) it does not matter so much, but get to 1080p++ and the cost becomes … extreme.

1,651,936 Screenshot_2017-04-16-21-23-50.png
1,701,243 Screenshot_2017-04-16-21-23-54.png

  323,789 Screenshot_2017-04-16-21-23-50.jpg
  288,995 Screenshot_2017-04-16-21-23-54.jpg

This also has super bad ramifications for PNG optimizers which take n2 or worse time as the image gets larger… here’s pngout.exe behavior by image size:

s1 → 2.1s
s2 → 2.2s

1280x720 (720p)
s1 → 3.7s
s2 → 3.2s

1920x1080 (1080p)
s1 → 32s
s2 → 33s

3840x2160 (4k)
s1 → 57s
s2 → 42s
1 Like

Yeah, larger res PNG’s are way bigger than JPEG’s. I am considering removing PNG’s from the approved files list; do any smartphones use PNG as the native capture format?

You shouldn’t need to worry, latest version of Discourse handles this perfectly and seamlessly. If Bad Users upload giant PNGs we auto-force-convert them as needed.


BTW, how large is considered giant?

Look in your site settings for the image related settings.

Sorry to be a pest, but the only image relevant settings I can find are max image size and max image megapixels.

Are you saying that pngs larger than max image megapixels will be converted to jpegs?

This is something you can pretty easily test for yourself on – give it a shot!

I know that it is probably not recommended approach, but I’d like to batch downsize uploads directory (original uploaded images not thumbnails) with external utility from bash. I’ve noticed that there is filesize column in uploads table so the question is: should I care about updating filesize field for each uploaded file that I’ll optimize outside of Discourse? Can I break something if not? From what I’ve found in sources uploads.filesize field is only used to display information in lightbox to user.

We need a proper custom script to do that, cause sha1 also should be updated and posts should be rebaked, optimized images need to be redone, it’s a pretty involved process


OK, thanks! I know I’ve forgot something… I will look into it more in detail…