Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial 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: http://www.imagemagick.org/script/license.php

SKEW


Applies a skew distortion to an image

Download Script

last modified: September 26, 2017



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.

ARGUMENTS:

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


EXAMPLES


Original

Horizontal Skew To Right (B2R)

Arguments:
-a 20 -m degrees -d b2r

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

Arguments:
-a 34 -m pixels -d b2r

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

Horizontal Skew To Left (B2L)

Arguments:
-a 20 -m degrees -d b2l

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

Arguments:
-a 34 -m pixels -d b2l

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

Vertical Skew To Bottom (R2B)

Arguments:
-a 20 -m degrees -d r2b

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

Arguments:
-a 34 -m pixels -d r2b

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

Vertical Skew To Top (R2T)

Arguments:
-a 20 -m degrees -d r2t

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

Arguments:
-a 34 -m pixels -d r2t

Arguments:
-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