Immediately Resize, Rotate, and Flip Images via Command Line with sips

Jul 13, 2010 - 12 Comments

sips command line image modification tool You can resize, rotate, or flip any image file via the Mac’s Terminal using the powerful command line sips tool. Manipulating images with sips is practically instantaneous, and if you need to quickly resize, rotate, or flip an image file and want to stay within the command line, it can definitely beat firing up a GUI application like Preview to perform the same image modification tasks. Note that sips changes the image file instantly, there is no confirmation required.

Let’s get started and learn how to quickly make some image edits and modifications with sips.

Resizing an Image with sips from Terminal

To instantly resize any image file with sips, you just need to use the following command syntax:

sips -z 600 800 test.jpg

The format for the sips -z flag is height first then width, so despite the command appearing dimensionally backwards to many computer users, the above command would resize an image to be 800 pixels wide by 600 high. You can adjust this as appropriate, either staying within the proportions as already set by the image, or even resizing a picture out of the usual restraints and going to a completely new size, just remember the command syntax and format for resizing is:

sips -z height width [file]

Rotating Images from sips at the Terminal

By default, sips rotates clockwise so you just need to specify the degrees you want an image rotated, like so:

sips -r 90 image.jpg

The file will immediately be rotated 90 degrees clockwise. Changing the degrees and the -r flag will set the rotation as appropriate, for example this would flip the image file as directed a total of 270°:

sips -r 270 image.jpg

To review, the command syntax for rotation is:

sips -r degree [file]

Flip an Image with sips in the Terminal

Using sips, you can also flip any image vertically or horizontally from the command line, here’s an example:

sips -f horizontal image.jpg

This will instantly flip image.jpg horizontally, you can just as easily flip the image vertically by replacing horizontal with vertical like so:

sips -f vertical image.jpg

For flipping images, the command syntax to remember is:

sips -f orientation [file]

Note that we used JPG files for the purpose of these example command syntax, but in fact you can use the sips command on almost any image file format, whether it’s PNG, TIFF, JPEG, GIF, PDF, PICT, and many others. Speaking of file formats, sips can also convert image files to new formats with a command as well as perform command line based batch resizing. Overall, sips is incredibly powerful, and if you’re a command line user and need to modify images, you’ll find plenty of usage for it. Check out all of our sips tips here.

.

Related articles:

Posted by: Bill Ellis in Command Line, Tips & Tricks

12 Comments

» Comments RSS Feed

  1. Tarchuletta says:

    For anyone wondering how to rotate COUNTER-CLOCKWISE, you have to put the angle in single quotes. The following code rotates test.image -30 degrees:

    sips -r ‘-30’ test.jpg

    EDIT: changed post to say “single quotes”

  2. Stan says:

    Beware…at least on El Capitan (10.11.4), “sips -r 90 foo.pdf”
    will quietly throw away all pages past the first one. (Not related to amount of rotation … probably a bug / limitation handling pdf files)

  3. wolpertinger says:

    Here be Dragons!

    I wanted to use this to simply rotate a tiff file by 90 degrees.
    After entering the command, I got the following error message (including typo):

    Error: Cannot to rename temporary file to NEWFILE.TIF

    and the original file was deleted!

    This on 10.9.4, SIPS version 10.4.4

    I have filed a bug report with Apple

    • wolpertinger says:

      Also, be aware that the command changes both the creation and the modification date of the files being processed.

    • wolpertinger says:

      Follow-Up to the above problem:

      Receiving a reply to my bug report, it turned out that there was an already rotated version of the image in the folder, but it was hidden. It looks like SIPS failed to replace the old file with the processed version.

      So if you encounter this problem, you should open the folder in Terminal and enter “ls -la” to show all the files. Chances are, a version of the file is still there.

    • James says:

      I got a similar message when I did not include –out before the name of the output file. When I put this right, there was no trouble.

  4. […] it still handles batch processing bulk photos just fine. Also, you can tweak and resize images from the command line tool sips, which requires usage of the Terminal and thus may be considered more advanced, but it can be […]

  5. nick says:

    Using this method… is there a way to batch resize images by percentage? ie… resize to 50% of the original size instead of having to specify the resolution.

  6. Vin says:

    Does sips open .eps images? Any alternative from command line to change the resolution of a .eps image? Thanks

  7. steve says:

    is there a way to run sips from command line quietly ie no messages?

  8. matt says:

    Hey,
    Do you know if there is a way to specify JPEG quality with sips? With the orientation example this shouldn’t matter as it is possible to change the orientation of a JPEG (I think in Exif rather than JFIF JPEGS?) via metadata so the image data is not recompressed, but I am intrigued to know what sips setting is for uncompressed (say TIFF) to JPEG?
    I can’t find it in the man page!

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site