This article shows you how to convert older Apple image files saved in the PICT format on a Linux command line. These files can have the endings pict, pic, pct or none at all. Normally using the command line you will stick to Imagemagick's convert tool to get this taks done, but since the PICT format can be kind of tricky, you might just get an error instead of a converted file.
When trying to convert an image file with the PICT format, using the convert tool from the Imagemagick suite, gives you the following error:
convert: improper image header `/tmp/magick-OUz9zPgx' @ error/pict.c/ReadPICTImage/870
Since you might have never needed to question imagemagick's abilities, you might start to think the file is damaged. BUT when looking at the file in a file browser like Caya or Nautilus, you might still see a thumbnail of the fil's content.
PICT files seem to not always be real image files. If you see the error above, they can also be one-frame video files. That's why you can see thumbnails in a file browser, but can not convert it with imagemagick. Because they are movie files, you can use tools like ffmpeg (avconf) or mplayer to still convert them to jpg or png.
Video encoding tools like ffmpeg can not only be used to convert whole video files, but also to take "screenshots" from single frames in a video. And this it exactly what we need here. The following command will take the very first frame (-ss 0) from ORIGINALFILE.PICT and convert it in the second best JPEG quality (-qscale:v 2) to CONVERTEDFILE.JPG
ffmpeg -qscale:v 2 -ss -0 -i "ORIGINALFILE.PICT" -an CONVERTEDFILE.JPG
The only thing you have to change are the filenames. If you want to convert an entire folder, read on.
Converting many PICT files at once
Since you need to tell the ffmpeg command not only which file to convert but also a name for the output file, you'll need a small script here. The following command would convert all files in the directory it is issues, and will saveall files with a .jpg file ending:
for i in *; do echo "$i"; ffmpeg -qscale:v 2 -ss -0 -i "$i" -an "$i".jpg;
Ffmpeg will skip all files that it can't handly automatically.
Writing a script to include all subfolder
If you have to deal with a big collection of photos, that might be save in subfolders for years, months, days or another logic, the option above will take you a long time. Instead you can write a little script that will do all the directory changing and reissuing the command above for you.
1. Choose a base folder
To make things easier, you should place all the PICT files you want to convert in a simple named base folder. For the following steps to work, create a folder named "pictures" in the /tmp folder and a subfolder called "convert inside it by issuing the following command:
mkdir /tmp/pictures && mkdir /tmp/pictures/convert
Copy all the folders with the PICT files you want to get converted in the /tmp/pictures/convert folder
2. Make sure all necessary tools are installed
To make this howto work, you'll need the packages imagemagick, sed and tree installed. Just issue the following command to make sure you have everything.
sudo apt-get install imagemagick tree sed
Those packages already installed, will just be skipped. Depending on your distribution most of it might already be installed by default.
3. First part of the script: create a list of folders and subfolder
Change to the "pictures" folder you created earlier with the following command.
Be sure to not be inside the subfolder "convert". Next: issue the following command to write a list of folders in a file named "script.1". The output will be manipulated by the sed command, to write an additional "cd" commands in front of the file name to make the script change into that directory. Furhtermore a && will be added to the end of the output, to make sure that the script later will only run when it's really in that directory.
tree -dfi | sed "s/^.\//cd\ \"/g" | sed 's/$/\"\ \&\&/g' > script.1
4. Second part of the script: adding the convert command to run in every subdirectory
The following command looks quite complex, yet it does nothing more than reading the file created in the step before, adding the ffmpeg convert command from the beginning of the article, changes back to the base folder and writes its output in a file named script.2
sed -e 's/$/\ for i in *; do echo "$i"; ffmpeg -qscale:v 2 -ss -0 -i "$i" -an "$i".jpg; done;\ cd\ \/tmp\/pictures/g' script.1 > script.2
Make sure that if you use another base folder, to replace the part "tmp\/pictures" with the folder you chose. Make sure to use a backslash \ before a slash / in the command
5. Making the script executable and execute it
The following command will make the script.2 file executable....
chmod u+x script.2
... and this one will actually execute your script:
Depending on the number of files, you might now see the converter action flying along for quite some time.