The following are some tricks I’ve learned over the years and that I tend to (re)use now and again.
Doing Perspective Transforms
During a recent project, I had to assemble a presentation with browser screenshots arranged in a perspective view, and it was too time-consuming to use a standard image editor and manually go through each image.
So I decided to figure out a way to do it automatically at the nearest possible opportunity, and here it is.
The easiest way for me is to use control points for an initial image. Here is a reasonably nice looking perspective for an (aprox.) 1280×720 image:
convert -verbose ScreenShot.png -matte -virtual-pixel transparent \ -distort Perspective '0,0,110,100 0,720,100,600 1280,0,1080,0 1280,720,1060,720' \ output.png
Which yields a pretty nice-looking effect for dropping into a presentation (the end result has a transparent background – see the next section for how to convert it properly into a JPEG):
You can then use the
-verbose output for subsequent images of varying sizes, with minor adjustments.
One of the stupidest tricks ever:
convert -scale 480 -quality 80 screenshot.png -strip -interlace Plane -bordercolor white -border 0x0 Image1.jpg
The -strip -interlace Plane above results in a smaller progressive JPEG, which may be of interest in many cases.
Batch Resizing and Cropping
Here’s a little
Makefile for batch processing photos for the Vodafone 520 photoframe, which has an 800×480 LCD. If you have 6.3.8 or above, use
800×480^ as the resize specifier for best results on the center crop:
OPTS=-resize 800 -gravity Center -crop 800x480+0+0 -quality 100 SOURCES=$(wildcard Source/*.jpg) JPEG=$(foreach file,$(SOURCES),$(subst Source/,Final/,$(file))) all: jpeg Final/%.jpg: Source/%.jpg convert $(OPTS) $^ $@ jpeg: $(JPEG) clean: rm -f $(JPEG)