Imagick::scaleImage


wizard apg

SCALES the size of an image.



<?php
  
bool 
public Imagick::scaleImage(
                                     
int $cols,
                                     
int $rows,
                                  
bool $bestfit = false,
                                  
bool $legacy = false
                                                      
);
  
?>

$cols


The width of image.



$rows


The height of image.



$bestfit


Specifies whether to automatically maintain the aspect ratio of image or not.

If true it will maintain else it won’t.



$legacy


Specify the legacy.





This function returns true on success.



  1 EXERCISE   

<?php

$image 
= PATH2IMGW . '/png/IMG1.png';
$image_result = 'img/results/IMG1sci721.png';
    
$w1 = 400;
$h1 = 500;
    
$b1 = 1;
$l1 = 0;

$imagick = new Imagick($image);
$imagick->scaleImage($w1, $h1, $b1, $l1);
$data = $imagick->getImageBlob();
        
$img = imagecreatefromstring($data);

imagepng($img, $image_result);

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

IMG1sci721.png

Columns = 400
Rows = 500

Bestfit = 1
Legacy = 0


img/results/IMG1sci721.png apr

  2 EXERCISE   

<?php

// Run this code several times

$image = PATH2IMGW . '/others/local.jpg';
$image_result = 'img/results/localsci722.jpg';
    
$w2 = mt_rand(0, 500);
$h2 = mt_rand(0, 500);
    
$b2 = mt_rand(0, 1);
$l2 = mt_rand(0, 1);
        
$imagick = new Imagick($image);
$imagick->scaleImage($w2, $h2, $b2, $l2);
$data = $imagick->getImageBlob();
    
$img = imagecreatefromstring($data);

imagejpeg($img, $image_result);

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



localsci722.jpg

Columns = 341
Rows = 411

Bestfit = 0
Legacy = 1


img/results/localsci722.jpg apr