Daejuan Jacobs bio photo

Daejuan Jacobs

The Writer

Email Twitter Facebook Google+ LinkedIn Tumblr Deviantart

One of the advantages to using the command line over a traditional GUI is the ability to do several complex operations with one or two lines of code. When I received roughly 27 PSD files in CMYK format from my artist there were two options, use a graphics program and manually export each file to a RGB TIFF file, or leverage ImageMagick via the command line. ImageMagick is an open source collection of software scripts available for Windows, OS X & Linux. There are plenty of interfaces available, and it is already used in a lot of commercial software.

I wanted to convert the PSD files into a lossless format I could use to import into Scribus to create create the actual comic. Instead of exporting each file via a graphics program like Krita or InDesign, I created a small bash script that iterates through all files that match my input and run the file conversion.

#!/bin/bash

SOURCE_DIRECTORY="/path/to/psdfiles"
DESTINATION_DIRECTORY="/path/to/output/TIFF"

#Assume PSD files are named something like "Page 1 color.psd"
#Output will be Page1-flat.tiff
find $SOURCE_DIRECTORY -iname "Page*.psd" -print0 | parallel -0 -j4 convert "{}" -flatten -profile ColorMatchRGB.icc $DESTINATION_DIRECTORY/Page{=s/[^0-9]//g=}.tiff && echo "Files Done"

I used GNU Parallel in order to make use of my multi-core cpu. The -j4 denotes using 4 cpu cores. I could have set this higher, but since I ran this on my desktop and not a server I didn’t want these conversions to take over my computer. The convert command is the actual ImageMagick command tool. The -flatten option tells it to flatten the psd layers, since some programs have issues with psd layers. I should also note, that if the PSD file has layers that are out of order, the -flatten option will not perform as intended. Here you will have to fix the PSD file so the layers are in order.

The Page{=s/[^0-9]//g=} code snippet tells the command to only take the integer from the input filename to use in the output filename.

The script above was tested on Linux. It should run on OS X with no modification, Windows may require some tweaking.