✅ How to bulk compress a directory of images until each individual image is under a set size?
I have a directory of 1200 images, some of which are and some of which aren't under 256KB. I need all images that are to be compressed, resized, etc until they are under 256KB with as minimal changes as possible...
I currently have Magick.NET in my project so I'd prefer to use that if possible, but I don't even know where to begin. Should I prefer compression? Resizing? Both? Something else?
2 Replies
is that not a requisite? how can you not know that you need an image of a specific resolution for example
In this code, the CompressImages method accepts the source directory, the destination directory, and the maximum file size (in bytes) as parameters. It iterates through all the files in the source directory, and for each image file, loads the image using a MagickImage object, then enters a loop that continuously reduces the image quality until its size does not exceed the preset maximum. Finally, the compressed image is saved to the destination directory.
I don't know if this can help you.