Bulk convert jpeg files to png using sips on mac

mac sips (scriptable image processing system) is a very handy tool to convert image from one format to another. This can also be used to automate converting bulk images. We’ll use sips to convert all jpeg images to png in this article.

Use sips to convert one file

Use the following command to convert on file from jpeg to png format:

$ sips -s format png myimage.jpeg --out myimage.png

Create bash script to bulk convert

Create a bash script and call it bulk_jpeg_to_pngs.sh and put the following content in it:

#!/bin/bash
DIR=$1
cd $DIR
for i in  *.jpeg ; do
  j=$(echo -n $i | sed -e 's/.jpeg/.png/g')
  echo "--converting $i to $j"
  sips -s format png "$i" --out "$j"
done

Run bash script to bulk convert

Create a folder imgdir and keep two jpeg files file1.jpeg and file2.jpeg in it. You can keep any number of files with any names. Run the following command:

$ chmod a+x bulk_jpeg_to_pngs.sh
$ ./bulk_jpeg_to_pngs.sh /pathto/imgdir
--converting file1.jpeg to file1.png
/pathto/imgdir/file1.jpeg
  /pathto/imgdir/file1.png
--converting file2.jpeg to file2.png
/pathto/imgdir/file2.jpeg
  /pathto/imgdir/file2.png

Make sure you take a backup of your image directory before running this command. This will avoid any accidental loss of file due to overwrite.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments