Compress Uploaded Images Using ImageMagic or PHP GD (Admin Choice)

frm

Well-known member
My suggestion is to use ImageMagic or PHP GD, whichever is selected by the admin, to compress images to their choice (say 40% to 80%) as well as resize them to a maximum width (which will obviously resize their height to keep the same ratio too).

This will save some people enormous disk space and could also run retroactively for older photos uploaded (possibly on the cron).

In order to not be a resource hog, it would also queue up all photos as well as run a cron job to process X images not compressed every X minutes/hours (with admin able to execute it, like all other cron jobs, at non-peak hours to get ahead on compressing). This is so that someone couldn't upload 100 images and all resources would fly over to ImageMagic/GD to compress and resize. Rather, they'd upload at 100% and slowly, but surely, all compress.

Using this method wouldn't rely on a 3rd party API (such as Smush It) which could change at a moment's notice, keeping XF on their feet to maintain API calls, and be easier to maintain going forward with the development of XF.
 
Upvote 29
we already compress to 85% quality when we are resizing or otherwise saving the image.
Is this template editable, or hard coded? Eg. can I already customise compression quality and settings, or it will need (this) suggestion?
If this is a hardcoded 85%, the easiest solution seems to be to a config.php variable for the compression/quality rate we wish to use moving forward.

I understand that we already have 85% for prior uploads (so there's no going back to 100% for them), but I would like to set the compression to 0 or quality 100 (and much lower than 85% on subsequent forums). The idea of the cron could then be dropped and older forums could set the compression at a different rate after compressing them even further.

I think this would be a happy medium and a quicker implementation.
 
Based on past posts (i have tinkered with this setting before)... the values are hardcoded in /src/XF/Image/Imagick.php and /src/XF/Image/Gd.php files.
 
Based on past posts (i have tinkered with this setting before)... the values are hardcoded in /src/XF/Image/Imagick.php and /src/XF/Image/Gd.php files.
Seems to me that it could rationally be made default (as is) to 85% unless something such as $config['imageCompression'] = 65; is specifically set in config.php to change it to 65% to save even more space (or in my case, 100).
 
Based on past posts (i have tinkered with this setting before)... the values are hardcoded in /src/XF/Image/Imagick.php and /src/XF/Image/Gd.php files.
Seems to me that it could rationally be made default (as is) to 85% unless something such as $config['imageCompression'] = 65; is specifically set in config.php to change it to 65% to save even more space (or in my case, 100).
Would I need to make a separate suggestion—supposing it's hardcoded—for this @Chris D or would the votes of Smush It + this imply that it'd be a popular implementation and a happy medium for XF core?
 
tbh, compression through this route is probably going to generate worse images than using dedicated image optimizers like mozjpeg. plus this only comes into effect if the image is resized on upload (image dimensions are larger than configured). images that are under set limits are not compressed using this setting at all i believe.
 
it is easy to check if images are compressed on just uploads. from what i have seen, file size matches after upload :) Imagick.php has two mentions of 85 quality. i imagine the other one is for quality of thumbnails which are also saved on every upload.
 
Any news on this, guys?

I was looking for a way to reduce my attachments sizes as well, and I thought that Imagemagick would do this. But then I realized that the pictures I upload are still untouched and there's no custom settings at all in ACP.

I agree with those ones saying that the set limit only retrieves an error. I don't see any job done over my uploaded images. It all keeps the same pixel size and weight... 🤷‍♂️
 
Having the ability to allow users to upload any size, and then just let xenforo compress and resize image seems like the ideal setup? Having to use tinyjpg each time I want to upload a image is tiresome and not quite userfriendly.
 
There are 2 add-ons that will use image compression (pngquant, gifsicle, jpegoptim) etc. on your existing uploads and new uploads as they happen. They both work fine.
 
There are 2 add-ons that will use image compression (pngquant, gifsicle, jpegoptim) etc. on your existing uploads and new uploads as they happen. They both work fine.
Yea, I use TL's image optimizer and its nice, seems to save 40% or so on our new site with not much content on it yet.
 
There are 2 add-ons that will use image compression (pngquant, gifsicle, jpegoptim) etc. on your existing uploads and new uploads as they happen. They both work fine.
Yea, I use TL's image optimizer and its nice, seems to save 40% or so on our new site with not much content on it yet.

Thank you guys, for sharing these options to me. This would be one of them right? https://xenforo.com/community/resources/image-optimizer-for-xf-2-0.6030/ Would you guys know the link to the second one?
 
Top Bottom