Compress uploaded images in Vanilla forum
Large images uploaded by forum users were clogging up my server. Rather than make changes to core vanilla code, I decided a simple solution would be to run a cron script that checks for "large" jpeg's, and compresses one image every 30 minutes.
This is the script I came up with.
I added these files to my public_html, and then added a run line to cron this command every 30 minutes:
/usr/local/bin/php /home/mywebsitedomain/public_html/compressimages.php
I'm not an experienced php developer, so critical eyes and feedback are welcome, as there's the possibility I'm making big mistakes. This seemed like a simple solution to this issue for my server at least, and it freed up a lot of space, and the settings I've chosen have negligible compromise on image quality.
Hopefully this helps someone, or at least draws dev attention for a need for an integrated feature like this.
Thanks all.
Comments
Great work, @pinchies! This should be a core feature in my opinion. 🙃
Am I wrong or since VF 3.1 you can set max width & height for uploads (that will be automatically resized if larger than what you set) and choose the image compression quality via a line on config.php?
The distinction here is sometimes people need to upload high res images. However, digital cameras often produce very poorly compressed files. This script specifically targets files that are larger than they need to be. It doesn’t resize the images.
Regarding features, unless it’s documented somewhere, then it doesn’t exist.🤷♂️
Thanks for this information. It useful
To compress images on your Vanilla forum without manual intervention, you can use this script: VanillaCompressImages. It runs every 30 minutes to find and compress large JPEGs, helping save server space while maintaining image quality. For a quick alternative, You can try jpeg compressor tool to manage image sizes directly on your forum uploads.
https://jpegcompressor.com/