Imagick::appendImages


wizard apg

APPEND a set of images vertically.



<?php

Imagick 
public Imagick::appendImages(bool $stack)
                                            
?>

$stack


By default or if false images are stacked left-to-right.

If true images are stacked top-to-bottom.





This function returns an Imagick instace on success.



AVAILABLE "imagick" FILTERS
STUDIED IN THIS TUTORIAL

1690 - ImageMagick 6.9.10-6
FILTER
CONSTANTVALABOUT
imagick::FILTER_UNDEFINED0 
imagick::FILTER_POINT1 
imagick::FILTER_BOX2 
imagick::FILTER_TRIANGLE3 
imagick::FILTER_HERMITE4 
imagick::FILTER_HANNING5 
imagick::FILTER_HAMMING6 
imagick::FILTER_BLACKMAN7 
imagick::FILTER_GAUSSIAN8 
imagick::FILTER_QUADRATIC9 
imagick::FILTER_CUBIC10 
imagick::FILTER_CATROM11 
imagick::FILTER_MITCHELL12 
imagick::FILTER_BESSEL13 
imagick::FILTER_SINC14 
imagick::FILTER_LANCZOS22 
ed48

  1 EXERCISE   

<?php

$str1img 
'img/results/apnd601.png';

$im = new Imagick();

$im->newImage(10050"green");
$im->newImage(10050"yellow");
$im->newImage(10050"blue");
$im->newImage(10050"white");

$im->resetIterator();
$combined $im->appendImages(true);

$combined->setImageFormat("png");

$img imagecreatefromstring($combined);

imagepng($img$str1img);

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

 RESULT   

apnd601.png

img/results/apnd601.png apr

  2 EXERCISE   

<?php

$str2img 
'img/results/apnd602.png';

$im = new Imagick();

$im->newImage(10050"green");
$im->newImage(10050"yellow");
$im->newImage(10050"blue");
$im->newImage(10050"white");

$im->resetIterator();
$combined $im->appendImages(false);

$combined->setImageFormat("png");

$img imagecreatefromstring($combined);

imagepng($img$str2img);

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

apnd602.png

img/results/apnd602.png apr

  3 EXERCISE   

<?php

function appendImages()
{
    
$images = [
        [
            
"img/png/IMG_0405.png",
            
"img/png/IMG_0406.png"
        
],
        [
            
"img/png/IMG_0449.png",
            
"img/png/IMG_0461.png"
        
]
    ];
    
    
$canvas = new Imagick();

    foreach (
$images as $imageRow) {
        
$rowImagick = new Imagick();
        
$rowImagick->setBackgroundColor('gray');
        foreach (
$imageRow as $image_path) {
            
$imagick = new Imagick(realpath($image_path));
            
$imagick->setImageBackgroundColor("gray");
            
$imagick->resizeimage(200200Imagick::FILTER_LANCZOS1.0true);
            
$rowImagick->addImage($imagick);
        }
        
$rowImagick->resetIterator();

        
$combinedRow $rowImagick->appendImages(true);
        
$canvas->addImage($combinedRow);
    }

    
$canvas->resetIterator();
    
    
$finalimage $canvas->appendImages(true);
    
$finalimage->setImageFormat('png');
    
     
$Data $canvas->getImageBlob();

$canvas->resetIterator();

$rimg3 "img/results/apnd603.png";

$img imagecreatefromstring($Data);

imagepng($img$rimg3);

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

?>

apnd603.png

img/results/apnd603.png apr

  4 EXERCISE   

<?php

function appendImages()
{
    
$images = [
        [
            
"img/png/IMG_0405.png",
            
"img/png/IMG_0406.png"
        
],
        [
            
"img/png/IMG_0449.png",
            
"img/png/IMG_0461.png"
        
]
    ];
    
    
$canvas = new Imagick();

    foreach (
$images as $imageRow) {
        
$rowImagick = new Imagick();
        
$rowImagick->setBackgroundColor('red');
        foreach (
$imageRow as $image_path) {
            
$imagick = new Imagick(realpath($image_path));
            
$imagick->setImageBackgroundColor("red");
            
$imagick->resizeimage(200200Imagick::FILTER_LANCZOS1.0true);
            
$rowImagick->addImage($imagick);
        }
        
$rowImagick->resetIterator();

        
$combinedRow $rowImagick->appendImages(false);
        
$canvas->addImage($combinedRow);
    }
   
    
$finalimage $canvas->appendImages(true);
    
    
$canvas->resetIterator();
    
    
$finalimage->setImageFormat('png');
    
    
$Data $canvas->getImageBlob();

$canvas->resetIterator();

$rimg4 "img/results/apn604.png";

$img imagecreatefromstring($Data);

imagepng($img$rimg4);

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

?>

  5 EXERCISE   

<?php

function appendImages()
{
    
$images = [
        [ 
"img/jpg/1.jpg",
            
"img/jpg/aa.jpg"],
        [ 
"img/jpg/3.jpg",
            
"img/jpg/2.jpg" 
               ];
    
    
$canvas = new Imagick();

    foreach (
$images as $imageRow) {
        
$rowImagick = new Imagick();
        
$rowImagick->setBackgroundColor('green');
        foreach (
$imageRow as $image_path) {
            
$imagick = new Imagick(realpath($image_path));
            
$imagick->setImageBackgroundColor("green");
            
$imagick->resizeimage(200200Imagick::FILTER_CUBIC1.0true);
            
$rowImagick->addImage($imagick);
        }
        
$rowImagick->resetIterator();

        
$combinedRow $rowImagick->appendImages(false);
        
$canvas->addImage($combinedRow);
    }
   
    
$finalimage $canvas->appendImages(true);
    
    
$canvas->resetIterator();
    
    
$finalimage->setImageFormat('jpg');
    
    
$Data $canvas->getImageBlob();

$canvas->resetIterator();

$rimg5 "img/results/apn605.jpg";

$img imagecreatefromstring($Data);

imagepng($img$rimg5);

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

?>

apn605.jpg

img/results/apn605.jpg apr