0
votes

I am receiving control of a website and I need to take care of an image compression process.

Right now, when uploading an image, it gets stored on the server with high quality and when the website's being cached, the image is getting compressed for the cache. So the cache has a compressed copy of the image while the original, high quality image, is still stored on the server. The tool which is responsible of doing what I have just described was developed by the current owner of the website and since I am not getting that tool I will need another one. The site is currently using Pydio and I have not seen any compression option there.

Since it seems I need a new tool for the image compression process, I want to know first what is the best practice, performance-wise, for handling the compression and I know there some good, experienced developers here.

I thought about some options:

  1. Keep it the way it is now, which is to store the original image on the server and when caching, compress it for the cache (Best compatibility with the website since this is what the tool currently being used doing).
  2. Compress all images the moment they are being uploaded and so I will have only the compressed images on the server and use them to cache (Save storage space, but don't know how to combine it with Pydio).
  3. Have a cron which will compress all the images which are not already compressed (Gives me the ability to upload images freely without worrying about compressing them, though the images will not be immediately compressed).
  4. Upload the image to a website which compresses the image and then take the outputted image and upload it (Really, sounds stupid and a lot of messing around in order to upload an image)..

What do you think will be the best practice, and why? Also, Is there a better practice for compressing the images?

Plus, if you know any tool which has an API for it or anything, I will be thankful to hear about it.

The website is built using PHP.

2
Image compression techniques vary as per different mime types images come with. For example, PNG with transparency would require different compression technique than a JPEG. Consider using this Image Optimization as your starting point. For tools, you can use open source software like optiPNG, gifsicle, mozjpeg, jpeg-archive for compression. But mostly your work would be to fine tune whatever tool you use for the compression-quality tradeoff.t6nand

2 Answers

0
votes

Since the question you're asking is a general-approach one, I will put my two-cents in.

On your approaches:

Option 4 - You could use some offline software or an external site for compression, but it seems tedious work. If I needed to upload one image per day, I would probably choose this option.

Option 2 - I would rather not do compression on upload since you lose the original image. Image compression can ruin some images very badly.

As for options 1&3 - I think it depends on the resources of your server, the number of images, the traffic of your site, etc. Generally, I prefer compressing/caching on request, not upload, but for a smaller site, it shouldn't make much difference.

As for the API - generally, you have two options: do the work on your server/site or use an external service.

When it comes to services, we use CloudImage, it has very simple API and it helps a lot with the compression process (and resizing if you need it). Also, you have the benefits of the CDN, which will boost the performance. Since you are using Pydio, I assume you need data security and privacy, so CloudImage may be a good option for you since they take the privacy stuff really seriously.

If you prefer to do this yourself, and given that you use PHP, I would recommend ImageMagick and the PHP library IMagick. You can control every parameter of the compression and the documentation is pretty good. The only downside is that to achieve best compression without losing quality, it is a bit of trial-and-error at first.

Good luck!

-2
votes

Send your image on Whatsapp to other, received Image will be compressed to the significance size