How To: Image processing and management

ImageMagick

  • Convert a batch of PNG images to JPG:
    mogrify -format jpg -quality 90 *.png
  • Convert a batch of PNG images to JPG, and resize to thumbnail:
    mogrify -format jpg -quality 90 -thumbnail 512 *.png

ExifTool

  • Encode an Exif date tag into photos (recursively, in a whole directory):
    exiftool -AllDates-= -AllDates="2008:01:01 12:00:00" -overwrite_original -r .
  • Remove the GPS Exif tag from photos:
    exiftool -gps:all= -xmp:geotag= image.jpg -overwrite_original *
  • Add Copyright tag to all JPG images in directory:
    exiftool *.jpg -Copyright="Copyright (c) Dmitry Brant."

ffmpeg

  • Create video (x264) from a series of still frames (png):
ffmpeg -r 60 -f image2 -s 600x360 -start_number 0 -i frame%d.png -vcodec libx264 -crf 18 -pix_fmt yuv420p test.mp4

(-r = frame rate, -crf = quality (lower is better))

ffmpeg -r 60 -f image2 -s 1280x720 -start_number 0 -i frame%d.png -vcodec libtheora -qscale:v 7 test.ogv
  • Convert video from one format (e.g. x265) to another format (e.g. x264), making use of Nvidia hardware acceleration (requires a build of ffmpeg that includes support for cuda):
ffmpeg -hwaccel cuda -i [input.mp4] -map 0 -c:v h264_nvenc -crf 17 -vf format=yuv420p -c:a copy [output.mp4]

Miscellaneous

  • Create a bitmap font for use with Python PIL from a TrueType font:
    Download the otf2bdf tool:
    Use the pilfont utility, or do it directly in Python.
    ./otf2bdf -p 10 -r 96 -o font.bdf font.ttf
    (-p = font size, -r = screen dpi)
  • Steganography for PNG files: zsteg
    zsteg -a filename.png
    zsteg -E [name] filename.png
  • Convert HEIC images to JPG (using heif-convert)
for f in *.HEIC; do heif-convert -q 100 $f $f.jpg; done