Create PNG/JPG file with commandline on Mac

The command-line convert utility in the ImageMagick suite can easily create an image of specified dimensions:

convert -size 200x200 xc:white canvas.png

To create an image with text, use additional options:

convert -size 200x200 -gravity center -background white -fill black \
        label:"text goes here" canvas.png

The ImageMagick site has many more examples of usage.

To get ImageMagick on OSX, you can either use an automated build system such as MacPorts or run a pre-made installer package.


OS X doesn't come with a shell command for this. But you have three options.

OS X does come with a way to do this in Applescript: Image Events. You could write a three-liner in Applescript—or Python or Ruby with appscript or ScriptingBridge—that does what you want, and then run that from the shell.

OS X also has some pretty high-level image support built into Cocoa, which you can access from Python, Ruby, ObjC, Applescript, etc., so you could write a five-liner that way that does what you want.

Or you could use a third-party tool that gives you what you want. ImageMagick, as suggested by user4815162342, is probably the best one.

(I wouldn't even mention the first two possibilities if you posted on SU rather than SO.)