Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts

Saturday, February 28, 2015

One-liner command for changing image resolution

The command in this post requires the GraphicsMagick package (see this for an explanation). GraphicsMagick commands start with gm in front of them.

Use the following command in Terminal, and GraphicsMagick will change your image resolution.
gm convert original.jpg -resize 120x120 output.jpg
The image will be scaled so its largest dimension is 120 pixels.

See this for an explanation of what other options are available for this command.

Wednesday, May 21, 2014

One-liner command for creating animated GIF

The command in this post requires the GraphicsMagick package (see this for an explanation). GraphicsMagick commands start with gm in front of them.

  • First have the individual frames of your animation ready, and give them similar ordered names, say frame01.png , frame02.png , frame03.png , etc. The numbers determine the order in which the frames will appear in the final animation.

  • Put all the frames in a folder (say, animFrames/ ).

  • Now use the following command in Terminal, and GraphicsMagick will convert your frames into an animation anim.gif .
    gm convert -delay 5 animFrames/frame*.png anim.gif
    
    The option -delay determines the delay between displaying frames (the unit is 1/100th of a second).

    See this for an explanation of what other options are available for this command.

Command-line graphics editors: GraphicsMagick and ImageMagick

GraphicsMagick and ImageMagick are both powerful command-line programs for manipulating various image types. They have similar syntax, except that GraphicsMagick commands start with gm while in ImageMagick different commands have different binaries, so you just type the command name directly. For instance, the command for converting file types to each other in GraphicsMagick is
gm convert originalFile targetFile
while in ImageMagick it would be
convert originalFile targetFile
I have found GraphicsMagick to be the faster of the two packages.

Thursday, March 6, 2014

One-liner command for changing pdf size

The commands in this post require the GraphicsMagick package (see this for an explanation). GraphicsMagick commands start with gm in front of them.

One use of these programs is to resize pdf files. I found a solution here, which was really helpful. I will repeat and expand on it.

 TLDR Version

Use the following command in terminal:
gm convert -density 300x300 -quality 25  -compress jpeg  originalFile.pdf targetFile.pdf

 Explanation

Now let's see what that command does. First the bare bones:
gm convert  -compress jpeg  originalFile.pdf targetFile.pdf
This command will compress your pdf file for you, but will use default values for the output's density and compression quality. Unfortunately, the resulting output is overly compressed and unusable for most uses.

-compress jpeg defines the type of image compression. Read more about it here.

Adding the -density 300x300 makes sure that the pdf's resolution is satisfactory. Read more about it here.

If the output file's size is till too big, you can either lower the above resolution, or increase the compression level of the pdf (and lower its quality). That is what the -quality 25 command does. The default value is at the higher quality of 75. The number can be anything from 0 (lowest quality) to 100 (highest quality).
Read more about -quality here.