skip to Main Content

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


  1. 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:

    enter image description here

    -rw-r--r--   1 mark  staff  161310 15 Feb 16:56 input.jpg
    

    You can reduce it to your desired 40kB with this command in Terminal (or Command Prompt if under Windows):

    magick input.jpg -define jpeg:extent=40kb result.jpg
    

    And the result is 39kB:

    -rw-r--r--   1 mark  staff   39119 15 Feb 16:58 result.jpg
    
    Login or Signup to reply.
  2. 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:

    • install node.js
    • install gulp
    • install the appropriate package managers
    • configure gulp to grab the images from a specific folder and transform them manually or automaticaly into your desired “output” folder.

    If you wanted to go down this route, I suggest you start learning more about gulp here:

    https://gulpjs.com/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search