Search code examples
macosbashcommand-linepng

Create PNG/JPG file with commandline on Mac


is there a command to create a simple PNG/JPG picture file, can be run in terminal/script command on Mac?

For now, I'm going to create a simple one color PNG picture file, with parameter to specify wide and length. if it can put text on it, is much better.


Solution

  • 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.