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 Functions page: 17

Roll image

Offsets an image as defined by x and y.

Roll image example
$im = new Imagick($input);
$im->rollImage( 20, 50 );
$im->writeImage('rollImage.jpg'); 
$im->destroy();

Rotate image

Rotates an image the specified number of degrees.

Rotate image example
$im = new Imagick($input);
$im->rotateImage( new ImagickPixel('none'), 7 );
$im->trimImage ( 0 );
$im->resetImagePage( '216x174+0+0' );
$im->writeImage('rotateImage.png'); 
$im->destroy();

( Empty triangles left over from rotating the image are filled with the background color. )

Round corners

Rounds image corners.

Round corners example
$im = new Imagick($input); 
$im->roundCorners(10, 10);
$im->writeImage( "roundCorners.png" );
$im->destroy();

// Alternative method for a coloured background and save as a jpg
/*
$input = 'DSCF0848.jpg';
$size = getimagesize($input);  
$background = new Imagick();
$background->newImage($size[0], $size[1], new ImagickPixel('red'));
$image = new Imagick($input);
$image->setImageFormat("png");
$image->roundCorners(10,10);
$image->compositeImage($background, imagick::COMPOSITE_DSTATOP, 0, 0);
$image->writeImage("rounded.jpg");
*/

( The first two parameters control the amount of rounding and the three last parameters can be used to fine-tune the rounding process. )

Sample image

Scales an image to the desired dimensions with pixel sampling.

Sample image example
$im = new Imagick($input); 
$im->sampleImage(100, 100);
$im->writeImage( "sampleImage.jpg" );
$im->destroy();

( Unlike other scaling methods, this method does not introduce any additional color into the scaled image. )

Scale image

Scales the size of an image to the given dimensions.

Scale image example
$im = new Imagick($input); 
$im->scaleImage(100, 100, TRUE);
$im->writeImage( "scaleImage.jpg" );
$im->destroy();

( The other parameter will be calculated if 0 is passed as either param. )

Segment image

Analyses the image and identifies units that are simila

Separate image channel

Separates a channel from the image and returns a grayscale image.

Separate image channel example
$im = new Imagick($input); 
$im->separateImagechannel( imagick::CHANNEL_RED );
$im->writeImage( 'separateImagechannel_r.jpg' );
$im->separateImagechannel( imagick::CHANNEL_BLUE );
$im->writeImage( 'separateImagechannel_b.jpg' );
$im->separateImagechannel( imagick::CHANNEL_GREEN );
$im->writeImage( 'separateImagechannel_g.jpg' );
$im->destroy();
// Join the 3 images to display
$im = new Imagick();
$im->readImage('separateImagechannel_r.jpg' );
$im->readImage('separateImagechannel_g.jpg' );
$im->readImage('separateImagechannel_b.jpg' );
$im->resetIterator();
$appended = $im->appendImages(TRUE);
$appended->writeImage('separateImagechannel.jpg'); 
$appended->destroy();

( A channel is a particular color component of each pixel in the image. )

Sepia tone image

Applies a special effect to the image, similar to the effect achieved in a photo darkroom by sepia toning.

Sepia tone image example
$im = new Imagick($input);
$im->sepiaToneImage( 80 );
$im->writeImage('sepiaToneImage.jpg'); 
$im->destroy();

( Threshold ranges from 0 to QuantumRange and is a measure of the extent of the sepia toning. A threshold of 80 is a good starting point for a reasonable tone. )

Set background color

Sets the object's default background color.

Set color

Sets the color described by the ImagickPixel object

The colours are the same within the tolerance

$im = new Imagick($input);
$pixel = $im->getImagePixelColor( 78, 22 );
$compair = new ImagickPixel();
$compair->setColor("rgb(105,134,6)");
$output = $compair->isSimilar($pixel, 0.2);
if ( $output ) { echo "
The colours are the same within the tolerance";} else echo "
The colours are Different"; $im->destroy();

( Sets the color described by the ImagickPixel object, with a string (e.g. "blue", "#0000ff", "rgb(0,0,255)", "cmyk(100,100,100,10)", etc.). )

Set colorspace

Sets the global colorspace value for the object.

$im = new Imagick($input);
$im->setImageColorSpace(Imagick::COLORSPACE_GRAY);
$im->sketchImage( 10, 0, 45 );
$im->writeImage('setImageColorSpace.jpg'); 
$im->destroy();

Set compression quality

Sets the object's default compression type.

Set compression quality example
$im = new Imagick($input);
$im->setCompressionQuality( 50 );
$im->writeImage('setCompressionQuality.jpg'); 
$im->destroy();

Set filename

Sets the filename before you read or write an image file.

Set first iterator

Sets the Imagick iterator to the first image.