Functions page: 16

Rotate image
Rotates an image the specified number of degrees.
Rotate image example

bool rotateImage ( mixed $background , float $degrees )

<?php 
$im 
= new Imagick($input);
$im->rotateImage( new ImagickPixel('none'), );
$im->trimImage );
$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

bool roundCorners ( float $x_rounding , float $y_rounding [, float $stroke_width = 10 [, float $displace = 5 [, float $size_correction = -6 ]]] )

<?php 
$im 
= new Imagick($input); 
$im->roundCorners(1010);
$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

bool sampleImage ( int $columns , int $rows )

<?php 
$im 
= new Imagick($input); 
$im->sampleImage(100100);
$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

bool scaleImage ( int $cols , int $rows [, bool $bestfit = false ] )

<?php 
$im 
= new Imagick($input); 
$im->scaleImage(100100TRUE);
$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
None

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

bool separateImageChannel ( int $channel )

<?php 
$im 
= new Imagick($input); 
$im->separateImagechannelimagick::CHANNEL_RED );
$im->writeImage'separateImagechannel_r.jpg' );
$im->separateImagechannelimagick::CHANNEL_BLUE );
$im->writeImage'separateImagechannel_b.jpg' );
$im->separateImagechannelimagick::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

bool sepiaToneImage ( float $threshold )

<?php 
$im 
= new Imagick($input);
$im->sepiaToneImage80 );
$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.
None

Set color
Sets the color described by the ImagickPixel object
The colours are the same within the tolerance


setColor ( string $color )

<?php 
$im 
= new Imagick($input);
$pixel $im->getImagePixelColor7822 );
$compair = new ImagickPixel();
$compair->setColor("rgb(105,134,6)");
$output $compair->isSimilar($pixel0.2);
if ( 
$output ) { echo "<br/>The colours are the same within the tolerance";}
else echo 
"<br/>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.
None


bool setColorspace ( int $COLORSPACE )

<?php 
$im 
= new Imagick($input);
$im->setImageColorSpace(Imagick::COLORSPACE_GRAY);
$im->sketchImage10045 );
$im->writeImage('setImageColorSpace.jpg'); 
$im->destroy();
 
?>
Set compression quality
Sets the object's default compression type.
Set compression quality example

bool setCompressionQuality ( int $quality )

<?php 
$im 
= new Imagick($input);
$im->setCompressionQuality50 );
$im->writeImage('setCompressionQuality.jpg'); 
$im->destroy();
 
?>
Set filename
Sets the filename before you read or write an image file.
None

Set first iterator
Sets the Imagick iterator to the first image.
None

Set font
Sets object's font property.
Set font example

bool setFont ( string $font )

<?php 
$width 
'200';
$height '100';
$text 'Rubblewebs';
$im = new Imagick();
$draw = new ImagickDraw();
$draw->setFont('arial.ttf');
$draw->setFontSize28 );
$fillcolor = new ImagickPixel"white" );
$draw->setFillColor$fillcolor );
$draw->setGravityImagick::GRAVITY_CENTER );
$bgcolor = new ImagickPixel'Black' );
$im->newImage($width$height$bgcolor );
$im->annotateImage($draw000$text);
$im->writeImage'setFont.jpg' );
$im->destroy();
 
?>


This method can be used for example to set font for caption: pseudo-format. The font needs to be configured in ImageMagick confiration or a file by the name of font must exist. This method should not be confused with ImagickDraw::setFont() which sets the font for a specific ImagickDraw object.
Set format
Sets the format of the Imagick object.
None