kuda.ai | code. guitar. life.

Transform .heic pictures on mac with sips in your terminal

created in July 2022

I use my iPhone to take pictures. Although they are all available in photos, I still tend to send those pictures to my macbook with airdrop. This could be, for instance, when I am sending an email and when I want to attach a picture to this email.

When you send your pictures from your iPhone to your Macbook with airdrop, they are in the format “HEIC” (high efficiency image file). I mostly need jpeg.

Another problem is that the file size is too large. Therefore, I usually reduce the resolution of the pictures, and I do it with several clicks with “Preview”.

Transforming images with “sips”

Macs have a terminal application called “sips” with which you can transform image files. (See: “sips MAN page Man Page - macOS - SS64.com”)

Change file format to jpeg

If, for example, I have the image IMG_42.heic on my desktop, I can transform it to jpeg with sips like so:

cd ~/Desktop/
sips \
  --setProperty format jpeg \
  --out IMG_42.jpeg \
  IMG_42.HEIC

Change file size

You can add an additional option to reduce the width of the picture. This will reduce the size of the file.

sips \
  --setProperty format jpeg \
  --out IMG_42.jpeg \
  --resampleWidth 1080 \
  IMG_42.HEIC

Change multiple files at once

What if you had multiple pictures that you want to transform? Doing it file by file would be cumbersome. We need a script! Here it is:

# script.sh
for file in $( ls | grep -i .heic );
do
  name=$( echo $file | cut -f1 -d. )
  sips \
    -s format jpeg \
    --resampleWidth 1080 \
    --out $name.jpeg \
    $file
done