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.
Imagick Distort functions page: 1
Affine
Distort the image linearly by moving a list of at least 3 or more sets of control points.
No exampleAffine projection
Linearly distort an image using the given Affine Matrix of 6 pre-calculated coefficients.
No exampleArc
Arc the image.
$im = new imagick( $input ); $distort = array( 180.0, 0.0 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_ARC, $distort, TRUE ); $im->writeImage('distort_arc.png'); $im->destroy();
Barrel
Given the four coefficients (A,B,C,D) as defined by Helmut Dersch, perform a barrel or pin-cushion distortion.
$im = new imagick( $input ); $distort = array( 0.0, 0.2, 0.0, 1.0 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_BARREL, $distort, TRUE ); $im->writeImage('distort_barrel.png'); $im->destroy();
Barrel inverse
This is very similar to 'Barrel' with the same set of arguments, and argument handling.
$im = new imagick( 'distort_bilinear.png' ); $distort = array( 0.0, 0.2, 0.0, 1.0 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_BARRELINVERSE, $distort, TRUE ); $im->writeImage('distort_barrelinverse.png'); $im->destroy();
Bilinear
Bilinear Distortion, given a minimum of 4 sets of coordinate pairs, or 16 values.
$im = new imagick( $input ); $distort = array( 0,0, 20,0, 213,0, 180,30, 213,160, 213,130, 0,160, 0,140 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_BILINEAR, $distort, TRUE ); $im->writeImage('distort_bilinear.png'); $im->destroy();
Perspective
Perspective distort the images, using a list of 4 or more sets of control points.
$im = new imagick( $input ); $corners = array( 0,0, 0,0, 200,0, 200,30, 200,150, 200,120, 0,150, 0,150 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_PERSPECTIVE, $corners, TRUE ); $im->writeImage('distort_perspective.png'); $im->destroy();
Perspective projection
Do a 'Perspective' distortion biased on a set of 8 pre-calculated coefficients.
No examplePolar
Like 'Arc' but do a complete Cartesian to Polar mapping of the image.
$im = new imagick( $input ); $distort = array( 100,20, 133,150, 180,270 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_POLAR, $distort, FALSE ); $im->writeImage('distort_polar.png'); $im->destroy();
Scale rotate translate
Distort image by first scaling and rotating about a given 'center', before translating that 'center' to the new location.
$im = new imagick( $input ); $distort = array( 28,24, .4,.8, -110, 50,120 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_SCALEROTATETRANSLATE, $distort, FALSE ); $im->writeImage('distort_scalerotatetranslate.png'); $im->destroy();
Shepards
Distort the given list control points (any number) using an Inverse Squared Distance Interpolation Method.
$im = new imagick( $input ); $distort = array( 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 ); $im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_TRANSPARENT ); $im->setImageMatte( TRUE ); $im->distortImage( Imagick::DISTORTION_SHEPARDS, $distort, FALSE ); $im->writeImage('distort_shepards.png'); $im->destroy();