loading...

resizing and optimizing images in terminal

bashjoey profile image bashjoey ・1 min read

Disclaimer: This tutorial assumes you're using Mac and Homebrew, do some google-fu for your particular situation.

Batch resizing pngs and optimizing quickly in Terminal for anyone else who may want a lil trick to save time!

Download ImageAlpha and ImageOptim and move them to your applications folder.

In terminal, type:

brew update

brew install imageoptim-cli

Then navigate to a directory holding all of the pngs you want to optimize, and type:

imageoptim --imagealpha '**/*.png'

This also works with a program called JPEGmini for optimizing jpg’s but I haven’t tried that out yet.

Now batch resizing! Navigate to the directory holding images you wish to resize. Let's say this time there are both pngs and jpgs in this directory and you want to resize them all to have a width of 640px and maintain their aspect ratio. Type:

sips -Z 640 *.png *.jpg

Badabing, badabang! This is how that line breaks down. sips is the program you’re running, -Z tells it to maintain the aspect ratio, 640 is the width you want to resize all the images as in pixels, and then the next part is you identifying which image types you are resizing, in this case both *.png *.jpg filetypes will be affected. If only png, all you’d need to have here is *.png.

ko-fi

Posted on by:

Discussion

pic
Editor guide