I need to create a simple application that allows me to drag and image(s) onto and it will opimize the image below a certian file size.
I currently have a long drawn-out process in Photoshop where I have to save multiple images at once, reopen each, and export as the correct file size. The dimensions are always the same though. So 300×300 will always be below 40kbs, while the 100×600 will always be 35kbs.
Even if I’m running the images through Photoshop the same exact way. I was just hoping there’d be a faster/automated process but I’m having a lot of trouble finding one.
Any ideas?
Thanks in advance.
Note: I don’t want to change the image size (dimensions) only the file size (kbs).
2
Answers
You can do that with ImageMagick which is installed on most Linux distros and is available for macOS and Windows. It only works for JPEG (because that allows trading image size for quality), whereas PNG does not – explicitly, at least.
So, say your image is 300×300 and particularly large at 161kB because it is incompressible random noise:
You can reduce it to your desired 40kB with this command in Terminal (or Command Prompt if under Windows):
And the result is 39kB:
For local use, I’d set up gulp and use npm packages (any package that can do what you need to do) along the lines of:
https://www.npmjs.com/package/gulp-image-resize – to resize images
https://www.npmjs.com/package/gulp-imagemin – to compress images (I know you can use the size parameter to target the desired filesizes, at least for jpegs)
But showing you how to set everything up step by step would be beyond the scope of this answer, so let me just give you a rough outline of what you’d need to do:
If you wanted to go down this route, I suggest you start learning more about gulp here:
https://gulpjs.com/