Convert Images in Terminal on a Mac

There is some wanky muss with my Piwigo install so I’ve been playing around with all sorts of things. One thing I found is that it no longer seems to like “.png” files as “pwg_representative” for video files. Okay fine, but seriously why all of a sudden? But I digress.. The built-in “sips” (Scriptable Image Processing System) command on a Mac is an easy way to convert a bunch of images from png to jpg. This also works with other formats by the way.

sips -s format jpeg My_Picture.png –out My_Picture.jpg

An oddity for sure is that after “format” you need “jpeg” not “jpg” and yet if you specify “My_Picture.jpeg” it will warn you that it changed your file name to “My_Picture.jpg”. Way to go Apple. Anyway its a useful command, as the name suggests, its good for scripting. Here is how I scripted it..

for PICTURE in `ls pwg_representative | grep png`; do sips -s format jpeg pwg_representative/$PICTURE –out pwg_jpg/`echo $PICTURE | sed ‘s/.png/.jpg/’`; done

Feel free to suggest a more elegant way to do it.


Generate Video Thumbnails using Terminal on a Mac

I use a hosted service that does not support video services like ffmpeg. That means that if I use a software package like Piwigo that supports automatic video thumbnailing, I can’t take advantage of that feature. I can however upload my own thumbnail of a video, and if its the same file name (ex: vacation.mp4 and vacation.png) then it will automatically apply that image to my video. I wasn’t able to find a thumbnail generator that worked well and was free. Enter Terminal and the built in services to a Mac.

qlmanage -t -s 512 your_video.mp4 -o .

This command will use the QuickLook Manager utility to generate a 512 sized thumbnail and output it to the current directory. I wrote a quick one-liner to generate for all the videos in my directory that I wanted to upload.

for i in `ls`; do qlmanage -t -s512 $i -o .; done

Then another one-liner to remove the double file extension.

for i in `ls | grep png`; do mv $i `echo $i | cut -d”.” -f1,3`; done

As with all of my scripts, its not the most elegant way to do it, but it works.

Change EXIF Data with ExifTool on a Mac

Ever want to change the EXIF data in your pictures? I’ve had this question responded to in the form of another very shortsighted question “Why would you want to do that?” Here are a few reasons why you might want to update your EXIF data.

  1. Your camera clock went wanky and your pictures came out with the default year of the camera (apparently the vacation we just had actually happened in 2006, at least according to iPhoto).
  2. You took pictures in another timezone, but your camera clock is still at home.
  3. You want to resize your photos but retain the EXIF data.

Right, so here is how to do it.

First, grab a brilliant little tool by Phil Harvey called ExifTool. Seriously, thanks a lot Phil, ExifTool really is brilliant. There is a metric butt-load of options for ExifTool, but if you need to just change the date/time the command goes something like this.

exiftool -AllDates=’2014:01:31 15:35:33′ -overwrite_original your_picture_file.jpg

So that’s nice, but how about 2-300 pictures? Here is the one-liner I used to change my sister’s camera photos that were set to the correct time and day but in 2006. There are for sure more elegant ways to write this. This was quick and what came to me so it fit the bill.

for PIC in `ls Camera/`; do DATE=2014:`exiftool ./Camera/$PIC | grep Create | cut -d’:’ -f3-6`; exiftool -AllDates=”$DATE” -overwrite_original ./Camera/$PIC; done

This changed the year in all the date stamps to 2013 while retaining month, day, and time information. Feel free to make it more extensible and elegant as you see fit.