Convert png jpg heic on MacOS, using sips

By Xah Lee. Date: . Last updated: .

What is sips

macOS has a image processing command line tool named sips

sips stand for Scriptable Image Processing System.

it can convert image formats, rotate, flip, resize, etc.

Get Image Width Height

# get width
sips -g pixelWidth xx.jpg

# get height
sips -g pixelHeight xx.jpg

# get both width and height
sips -g pixelWidth -g pixelHeight xx.jpg

# sample output
# /Users/xah/Desktop/xx.jpg
#   pixelWidth: 1024
#   pixelHeight: 768

convert

# convert one png to jpg
sips -s format jpeg x.png --out x.jpg

resize

# resize to 500 by 500
sips -z 500 500 x.png --out x2.png
# Resize the largest side, keep aspect ratio
sips -z 600 old.jpg --out new.jpg

Overwrite Original

to overwrite original, just don't use the parameter --out

do all files in a dir

# convert all png to jpg, in current dir
function png_to_jpg {
    for xx in *.png; do sips -s format jpeg $xx --out $xx.jpg && rm $xx; done
    for xx in *.png.jpg; do mv $xx "${xx%.png.jpg}.jpg"; done
}

sips supported formats

sips --formats

Supported Formats:
-------------------------------------------
com.adobe.pdf                pdf   Writable
com.adobe.photoshop-image    psd   Writable
com.adobe.raw-image          dng
com.apple.atx                --    Writable
com.apple.icns               icns  Writable
com.apple.pict               pict
com.canon.cr2-raw-image      cr2
com.canon.cr3-raw-image      cr3
com.canon.crw-raw-image      crw
com.canon.tif-raw-image      tif
com.compuserve.gif           gif   Writable
com.dxo.raw-image            dxo
com.epson.raw-image          erf
com.fuji.raw-image           raf
com.hasselblad.3fr-raw-image 3fr
com.hasselblad.fff-raw-image fff
com.ilm.openexr-image        exr   Writable
com.kodak.raw-image          dcr
com.konicaminolta.raw-image  mrw
com.leafamerica.raw-image    mos
com.leica.raw-image          raw
com.leica.rwl-raw-image      rwl
com.microsoft.bmp            bmp   Writable
com.microsoft.cur            --
com.microsoft.dds            dds   Writable
com.microsoft.ico            ico   Writable
com.nikon.nefx-raw-image     nefx
com.nikon.nrw-raw-image      nrw
com.nikon.raw-image          nef
com.olympus.or-raw-image     orf
com.olympus.raw-image        orf
com.olympus.sr-raw-image     orf
com.panasonic.raw-image      raw
com.panasonic.rw2-raw-image  rw2
com.pentax.raw-image         pef
com.phaseone.raw-image       iiq
com.samsung.raw-image        srw
com.sgi.sgi-image            sgi
com.sony.arw-raw-image       arw
com.sony.axr-raw-image       axr
com.sony.raw-image           srf
com.sony.sr2-raw-image       sr2
com.truevision.tga-image     tga   Writable
org.khronos.astc             astc  Writable
org.khronos.ktx              ktx   Writable
org.khronos.ktx2             --    Writable
org.nema.dicom               dcm
org.webmproject.webp         webp
public.avci                  avci
public.avif                  avif  Writable
public.avis                  --
public.heic                  heic  Writable
public.heics                 heics Writable
public.heif                  heif
public.jpeg                  jpeg  Writable
public.jpeg-2000             jp2   Writable
public.jpeg-xl               jxl
public.mpo-image             mpo
public.pbm                   pbm   Writable
public.png                   png   Writable
public.pvr                   pvr   Writable
public.radiance              pic
public.svg-image             svg
public.tiff                  tiff  Writable

Reference

macOS sips image processing

image processing