How to convert PSD to JPG or PNG on Linux with Gimp CLI/batch mode (or other server-side tool)

command lineconversiongimpjpegpsd

I've been working on a theoretically simple web service to convert PSD or AI files to jpeg, png or some web-compatible format.

I was able to successfully use ImageMagic's convert -flatten sample.ai sample-ai.jpg command, but consistently getting "invalid header" for various attempts using PhotoShop PSDs. I'm assuming ImageMagick prefers it's own or GIMP-saved PSD files, though perhaps I'm missing something there.

Also tried installing NConvert, but had problems with glibc version on client's CentOS 5.8, which I'm not permitted to change.

In any case, GIMP seems to have good PSD support. More than enough to flatten an image and save it. They've also recently updated their PSD parser. I've seen a similar question but

  1. that's on windows,
  2. they didn't really answer anything for GIMP,
  3. neither convert nor mogrify works for me

mogrify: Improper image header 'Test1.psd'.

So, does anyone know how to write a conversion script in Gimp via command line? I'm looking at this article trying to figure out the commands, but I think my trouble is I don't know ScriptFu worth anything.

It would also be tremendously helpful if I can echo back the dimensions of the original PSD, but I can get these from the resulting file fairly easily with a second step.

Best Answer

I have just created a Node module that deals with PSD files from the CLI. You may use it with as many files as you want with just one command.

As far as my tests went, GIMP is not really a solution and has a poor understanding of modern PSD files, and NodeJS happen to have a great new package that deals with the Photoshop format.

Instructions from the GitHub repo:

Install it:

npm install -g psd-cli

Convert myfile.psd to a new myfile.png :

psd myfile.psd

I hope you find this useful! The package is pretty new and other cool features will be added soon. Any feature requests and help with improving the code is appreciated :)

Related Question