Fred's ImageMagick Scripts


    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at:

    Please read the Pointers For Use on my home page to properly install and customize my scripts.


Applies a skew distortion to an image

Download Script

last modified: December 15, 2018

USAGE: skew [-a amount] [-m mode] [-d direction] [-v vpmethod] [-b bgcolor] infile outfile
USAGE: skew [-h or -help]

-a .... amount ......... amount of skew as either degrees or pixels as
........................ specified by mode; default=0
-m .... mode ........... degrees or pixels; default=degrees
-d .... direction ...... b2r, b2l, r2b or r2t; first letter indicates
........................ which edge (bottom or right) to skew and the
........................ last letter indicates which direction to skew
........................ (right, left, bottom or top); default=b2r
-v .... vpmethod ....... virtual-pixel method to fill background area
........................ around skewed region; default=transparent
-b .... bgcolor ........ skew fill color when vpmethod=background; any
........................ IM color specification or none; default is white

PURPOSE: Applies a skew distortion to an image.

DESCRIPTION: SKEW applies a skew distortion to an image in either the X or the Y direction. The amount of skew can be specified in degrees or pixels.


-a amount ... AMOUNT of skew in either degrees or pixels as specified by the mode parameter. The default is 0 or no skew.

-m mode ... MODE specifies whether the amount is in degrees or pixels. The default is degrees.

-d direction ... DIRECTION specifies whether the skew is horizontal or vertical and at the same time whether positive or negative. This is done via the following options: b2r, b2l, r2b or r2t. These stand for: shift the bottom edge to the right, shift the bottom edge to the left, shift the right edge to the bottom and shift the right edge to the top. The default is b2r (shift the bottom edge to the right).

-v vpmethod ... VPMETHOD is the virtual-pixel method to use to fill the area added due to the skew. Any valid IM virtual-pixel method is allowed. The default is background.

-b bgcolor ... BGCOLOR specifies the background color to use as the fill color for areas added due to the skew when the virtual-pixel method is background. Any valid IM color may be used including none. The default is none. Note that none will only provide transparency for the fill areas, if the output image type supports transparency, e.g. png or gif. If none is specified and the output type does not support transparency, such as for jpg, then the resulting fill color will end up black.

IMPORTANT: This script works properly as of IM 6.4.2-7 when some fixes were made to -affine -transform. For IM versions prior to this, the script will work to skew the image. The virtual-pixel methods are ignored, But background color control may not work as specified. Results may end up with transparent areas even if undesired for output image types that support transparency, such as gif and png. Also there may be an artifact showing for -d r2l results, especially when the background is transparent.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.



Horizontal Skew To Right (B2R)

-a 20 -m degrees -d b2r

-a 20 -m degrees -d b2r -v white

-a 34 -m pixels -d b2r

-a 34 -m pixels -d b2r -v white

Horizontal Skew To Left (B2L)

-a 20 -m degrees -d b2l

-a 20 -m degrees -d b2l -v white

-a 34 -m pixels -d b2l

-a 34 -m pixels -d b2l -v white

Vertical Skew To Bottom (R2B)

-a 20 -m degrees -d r2b

-a 20 -m degrees -d r2b -v white

-a 34 -m pixels -d r2b

-a 34 -m pixels -d r2b -v white

Vertical Skew To Top (R2T)

-a 20 -m degrees -d r2t

-a 20 -m degrees -d r2t -v white

-a 34 -m pixels -d r2t

-a 34 -m pixels -d r2t -v white

What the script does is as follows:

  • Uses -transform with computed coefficients from -affine to perform a skew

This is equivalent to the following IM commands for the
case of skewing the bottom edge to the right 34 pixels with
a transparent background

  • sinang=`convert $infile -format "%[fx:$amount/h]" info:`
  • convert $tmpA -affine 1,0,$sinang,1,0,0 \
    -channel rgba -alpha on -virtual-pixel transparent \
    -transform $outfile