Rubblewebs

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 example

Affine projection

Linearly distort an image using the given Affine Matrix of 6 pre-calculated coefficients.

No example

Arc

Arc the image.

Arc example
$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.

Barrel example
$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.

Barrel inverse example
$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.

Bilinear example
$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();

Depolar

Uses the same arguments and meanings as a 'Polar' distortion but generates the reverse.

Depolar example

Perspective

Perspective distort the images, using a list of 4 or more sets of control points.

Perspective example
$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 example

Polar

Like 'Arc' but do a complete Cartesian to Polar mapping of the image.

Polar example
$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();

Polynomial

Can not find any notes for this

Scale rotate translate

Distort image by first scaling and rotating about a given 'center', before translating that 'center' to the new location.

Scale rotate translate example
$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();

Sentinel

Can not find any notes for this

Shepards

Distort the given list control points (any number) using an Inverse Squared Distance Interpolation Method.

Shepards example
$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();