SMF 2.1.2 has been released! Take it for a spin! Read more.

Main Menu

Image compression

Started by eldublu, March 11, 2014, 06:42:40 PM

Previous topic - Next topic


We run a forum where members upload images of the night sky. It's apparent that the images are being compressed, this is seen as pixellation in the dark areas of the image. We've got compressed output turned off and have set the maximum image size much higher than is normally uploaded.
Can anyone advise on what might be causing this? Ideally, we'd like to be able to display the images so they look exactly the same as the original.

Thanks in advance.


These images are posted as attachments, yes? If so, is "Re-encode potentially dangerous image attachments" checked, in the attachment settings?

I'm not, entirely, sure what that setting does and the wiki is about as helpful as a pork pie at a Barmitzvah, on that. But, I would assume that recoding could well result in some degradation.


Jpeg is a lossey format, so that each time an image is reformatted it will pick up more artifacts and not look as nice as it once did.

One way around this is to change the compression factor which by default is at 75. In Subs-Graphics.php in the Sources folder look for the following line:

$success = imagejpeg($dst_img, $destName);

And change it to:

$success = imagejpeg($dst_img, $destName, 85);

Around 85 seems to be a good number to use. Although by increasing that, the file size will increase also.

Another solution would be to encourage your members to upload those files in the .png. format. Which is not lossey and due to the limited colours in the image should also result in a much smaller file size.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods


You know... Because I'd assumed that these were quality images, I'd also assumed that they'd be in PNG or, even BMP format.

But, yes. What Kays says is 100% correct, if you're using JPG files.

In fact, if these files are going to be edited, for whatever reason, you're best converting them to BMP, editing them and, when all edits are done, convert them to the final format that you want to use. By their very nature, JPG files are extremely lossy, as Kays said. Each time you edit/save them, their quality will degrade, quite noticeably.


In posts am using thumbnails only, when clicked to view\download, the original pictures has no compression or loss whatsoever, they are exactly as uploaded with exact same filesize. The quality of the attachment system is one of the things in smf I highly appreciate.
2.0.19, php 8.0.23, MariaDB 10.5.15. Mods: Contact Page, Like Posts, Responsive Curve, Search Focus Dropdown, Add Join Date to Post.


Incidentally, the wiki article pertaining to image attachments and avatars now has revised descriptions which should alleviate any further confusion about how these functions work ;).
Soñando con una playa donde brilla el sol, un arco iris ilumina el cielo, y el mar espejea iridescentemente



Thanks for the advice.

@Kays, altered the compression as you suggested and it works a treat, thanks.  :)