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.

R_JphreaksubdreamerAolee

Comments

  • subdreamersubdreamer San Jose, CA

    Great work, @pinchies! This should be a core feature in my opinion. 🙃

    pinchies
  • edited September 30

    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?

    pinchies
  • pinchiespinchies New
    edited September 30

    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.🤷‍♂️

    subdreamer
  • Thanks for this information. It useful

    pinchies
Sign In or Register to comment.