I have about 280 Illustrator .ai files that I need to convert into .png files with a finished size of 500px x 500px. All of them aren't squared, so those that are, for example rectangular, need to be centered in the image and the background needs to be transparent.

Is there an easier way to do this because I wouldn't like to spend time converting them manually.

  • It depends on what operating system you're on. If you're comfortable with using the command line and can install Imagemagick, I recommend that. – Alex Blackwood Nov 12 '13 at 19:29
  • Isn't ImageMagic cross-platform? Could you provide an example? – MikkoP Nov 12 '13 at 19:58
  • Sure, check my answer below. – Alex Blackwood Nov 12 '13 at 20:20

If you have imagemagick installed, you can run the following command:

convert -colorspace RGB \
-background transparent \
-resize 500x500 \
-gravity center \
-extent 500x500 \
yourfile.ai outputfile.png

How you iterate over all files in a directory depends on your environment, of course, but something like this should work for bash:

for i in *.ai; do convert -colorspace RGB -background transparent -resize 500x500 -gravity center -extent 500x500 "$i" "$i.png"; done
  • That's a good solution but looking at your code wouldn't all the images have to be square and not rectangular because it will transform all the documents to 500px x 500px? – DᴀʀᴛʜVᴀᴅᴇʀ Nov 12 '13 at 21:23
  • No, the -resize switch respects the input image's aspect ratio. The -extent switch then creates the padding, if needed. – Alex Blackwood Nov 12 '13 at 21:37
  • It says no images defined output.png. See full error log: pastebin.com/mAmhqW6Y – MikkoP Nov 13 '13 at 10:12
  • Hmm. Looks like you're missing Ghostscript, which is required to interpret pdf files. If you do a search for Imagemagick Postscript delegate failed you should be able to find a solution. – Alex Blackwood Nov 13 '13 at 16:21
  • I downloaded Ghostscript from this website. Now I get this error. pastebin.com/Xp3SixjK That path is correct. I tried it with forward slashes too, no difference. – MikkoP Nov 13 '13 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.