Terminal, the wonder application, can do many things. This little trick, which I found over at BittBox, is to convert an image file from one format to another. Although you can save out images using preview or another graphical application. This is just as fun and just as simple. All you need is Terminal and a test file to test it out.
The first step is to change your current directory in Terminal to where you host file is. This saves on typing later on. Use the “cd” command and then the path to your directory where you file is stored. Once as you have done this type the following:
sips -s format bmp input.png --out output.bmp
This uses the scriptable image processing system program on your Mac. The -s option dedicates the format in this case bitmap. You can use the majority of the main formats:jpeg, tiff, png, gif, jp2, pict, bmp, and a whole load of others I can’t remember. You then need to specify a file, I have just typed the name since I have used the change directory command, you can list a path to a file if you want. The final section is –out and the output name which can be the same name as the input. You need to specify a file extension on both otherwise it will not create an image file, just a file.
You can also use an option “-z” after the file type specified. This is a resize option. For example the following:
sips -s format bmp -z 20 20 input.png --out output.bmp
Will convert the image to bmp and then resize it to 20px x 20px. This does produce an error about colour space, but it does seem to generate the file correctly.
If you want to do more image processing you can also flip and rotate the image using the following commands before you specify your images.
The first variable will rotate the image 50 degress clockwise. You can’t rotate counterclockwise. The second variable will flip the image either horizontal or vertical.
It is quite fun and very useful to use. You don’t need to open up Preview or Photoshop to manipulate and image, you can convert, resize and rotate using Terminal. Very useful and quick.
If you want to take your skills with Terminal a bit further I recommend you check out the Terminal Category on this site. If you fancy reading a book there is a couple on Amazon that I regularly see mentioned and recommend, O’reilly Unix Geeks and Unix Under the Hood both are designed for Mac OS X and take Terminal further.