Imagick::cropImage


wizard apg

EXTRACTS the region in a image.



<?php

bool 
public Imagick::cropImage(
                          
int $width,
                          
int $height,
                          
int $x,
                          
int $y
                                  
);

?>

$width


The width of the crop.



$height


The height of the crop.



$x


The X coordinate of the cropped region's top left corner.



$y


The Y coordinate of the cropped region's top left corner.





This function returns true on success.



  1 EXERCISE   

<?php

// Run this exercise several times
// For each new time, a new image will be shown

$img1 = new imagick(PATH2IMGW '/jpg/aa.jpg');
$str1img 'img/results/6aa new.jpg';

// Randon numbers

$w1 mt_rand(10$img1->getImageWidth());

$h1 mt_rand(10$img1->getImageHeight());

$x1 $w1;

$y1 $h1;

// You should try other values

$img1->cropImage($w1$h1$x1$y1);

$strg $img1->getImageBlob();

// Reads the STRING of getImageBlob() with the PHP GD library

$img imagecreatefromstring($strg);

imagejpeg($img$str1img);

echo 
basename($str1img); ?>
<br><br>
<img src="<?php echo $str1img?>"
 alt="<?php echo $str1img?>
 title="<?php echo $str1img?>">

6aa new.jpg

(width = 60%)

img/results/6aa new.jpg apr