How to resize images using terminal on Mac OSX?

ImageMacosTerminal

Image Problem Overview


I need a simple and free way to resize images and do batch jobs, if necessary. Free image manipulation software has been trickier to use than it should be.

Image Solutions


Solution 1 - Image

As pointed out by LifeHacker, the following command will do this very easily:

sips -Z 640 *.jpg

To quote their explanation:

"sips is the command being used and -Z tells it to maintain the image's aspect ratio. "640" is the maximum height and width to be used and "*.jpg" instructs your computer to downsize every image ending in .jpg. It's really simple and shrinks your images very quickly. Be sure to make a copy first if you want to preserve their larger size as well."

Source: http://lifehacker.com/5962420/batch-resize-images-quickly-in-the-os-x-terminal

Solution 2 - Image

imagemagick helps:

$ convert foo.jpg -resize 50% bar.jpg

There are a lot more things it can do, including the conversion between formats, applying effects, crop, colorize and much, much more.

Solution 3 - Image

Here is script that uses sips to recursively resize all the images in a given folder (and its sub-folders), and places the resized images in a resized folder on the same tree level as the image: https://gist.github.com/lopespm/893f323a04fcc59466d7

#!/bin/bash
# This script resizes all the images it finds in a folder (and its subfolders) and resizes them
# The resized image is placed in the /resized folder which will reside in the same directory as the image
#
# Usage: > ./batch_resize.sh

initial_folder="/your/images/folder" # You can use "." to target the folder in which you are running the script for example
resized_folder_name="resized"

all_images=$(find -E $initial_folder -iregex ".*\.(jpg|gif|png|jpeg)")

while read -r image_full_path; do
    filename=$(basename "$image_full_path");
    source_folder=$(dirname "$image_full_path");
    destination_folder=$source_folder"/"$resized_folder_name"/";
    destination_full_path=$destination_folder$filename;

    if [ ! -z "$image_full_path" -a "$image_full_path" != " " ] &&
        # Do not resize images inside a folder that was already resized
        [ "$(basename "$source_folder")" != "$resized_folder_name" ]; then 

        mkdir "$destination_folder";
        sips -Z 700 "$image_full_path" --out "$destination_full_path";

    fi

done <<< "$all_images"

Solution 4 - Image

Previous answers are correct, you can use mogrify too. For example, if you want to reduce the size of many images in a directory by 60% then you can use the command below:

of course always make a backup of your images in to another directory before playing with this command.

mogrify -resize 60% *

Solution 5 - Image

magic trick for itunesconnect :)

    mkdir ./iPhone5-5-Portrait
    sips -z 2208 1242 *.jpg -s formatOptions 70 --out ./iPhone5-5-Portrait
    sips -z 2208 1242 *.png --out ./iPhone5-5-Portrait

Solution 6 - Image

Additionally of @grepit reply

The correct syntax is:

magick mogrify -resize 60% *

And you need to install ImageMagick, the easiest way is using homebrew:

brew install imagemagick

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarcel GruberView Question on Stackoverflow
Solution 1 - ImageMarcel GruberView Answer on Stackoverflow
Solution 2 - ImageL3viathanView Answer on Stackoverflow
Solution 3 - ImagePedro LopesView Answer on Stackoverflow
Solution 4 - ImagegrepitView Answer on Stackoverflow
Solution 5 - Imageuser3682947View Answer on Stackoverflow
Solution 6 - ImagemaiconpeixinhoView Answer on Stackoverflow