THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
Distort the image linearly by moving a list of at least 3 or more sets of control points
$cmd = " $input -virtual-pixel transparent -distort Affine \"0,0 30,30 100,0 150,0 213,160 213,140\" "; exec("convert $cmd affine.png");
Linearly distort an image using the given Affine Matrix of 6 pre-calculated coefficients
More information to follow.$cmd = " $input -matte -virtual-pixel Transparent ". " +distort AffineProjection \"1,.006,0,1,0,0\" +repage "; exec("convert $cmd AffineProjection.png");
Arc the image (variation of polar mapping) over the angle given around a circle.
$cmd = "$input -matte -virtual-pixel transparent -distort arc 180"; exec("convert $cmd arc.png");
Given the four coefficients (A,B,C,D) as defined by Helmut Dersch, perform a barrel or pin-cushion distortion appropriate to correct radial lens distortions.
$cmd = "$input -matte -virtual-pixel transparent". " -distort barrel \" 0.0 0.2 0.0 1.0 \" -trim"; exec("convert $cmd barrel.png");
This is very similar to 'Barrel' with the same set of arguments, and argument handling. However it uses the inverse of the radial polynomial.
More information to follow.$cmd = "$input -matte -virtual-pixel transparent". " -distort BarrelInverse \" 0.0 0.0 -0.2 1.0 \" -trim"; exec("convert $cmd barrelInverse.png");
Bilinear Distortion, given a minimum of 4 sets of coordinate pairs, or 16 values.
$cmd = "$input -matte -virtual-pixel transparent ". " -interpolate Spline ". " -distort BilinearForward \"0,0 20,0 213,0 180,30 213,160 213,130 0,160 0,140\" "; exec("convert $cmd bilinearforward.png");
Bilinear Distortion, given a minimum of 4 sets of coordinate pairs, or 16 values.
$cmd = " bilinearforward.png -matte -virtual-pixel black ". " -distort BilinearForward \"20,0 0,0 180,30 213,0 213,130 213,160 0,140 0,160\" "; exec("convert $cmd bilinearreverse.png");
( Reversing the Bilinear forward effect. )
Uses the same arguments and meanings as a 'Polar' distortion but generates the reverse Polar to Cartesian distortion.
$cmd = "polar.png -matte -virtual-pixel transparent". " -distort depolar \"100,20 133,100 180,270\" "; exec("convert $cmd depolar.png");
( Opposite effect to polar. )
Perspective distort the images, using a list of 4 or more sets of control points.
$cmd = "$input -matte -virtual-pixel transparent". " -distort Perspective \"0,0 0,0 213,0 213,20 213,160 213,140 0,160 0,160 \" "; exec("convert $cmd perspective.png");
( The later control points are in a different order to the earlier versions. )
Do a 'Perspective' distortion biased on a set of 8 pre-calculated coefficients.
More information to follow.$cmd = "$input -alpha set -virtual-pixel transparent ". " -distort Perspective-Projection \"1.40, 0.25, 3.0 0.15, 1.30, 0.0 0.007, 0.009' \" "; exec("convert $cmd Perspective_Projection.png");
Like 'Arc' but do a complete Cartesian to Polar mapping of the image.
$cmd = "$input -matte -virtual-pixel transparent". " -distort polar \"100,20 133,100 180,270\" "; exec("convert $cmd polar.png");
Distort image by first scaling and rotating about a given 'center', before translating that 'center' to the new location, in that order.
$cmd = " $input -matte -virtual-pixel transparent ". " -distort ScaleRotateTranslate \"28,24 .4,.8 -110 50,120 \" "; exec("convert $cmd srt.png");
( Also known as SRT )
Distort the given list control points (any number) using an Inverse Squared Distance Interpolation Method.
$cmd = "$input -matte -virtual-pixel transparent". " -distort Shepards \"0,0 0,0 0,100 20,100 0,200". " 0,200 133,200 133,180 266,200 266,200 266,100". " 246,100 266,0 266,0 133,0 133,20\" "; exec("convert $cmd shepards.png");