Search code examples
phpimagick

insert image into another image Imagick


I need to create an image with Imagick php with white background of a certain size (45 cm wide x 32 cm high) and copy him within an image that I have in a folder in a certain fixed position.

I could help with this?

A greeting and thank you very much


Solution

  • imagecopy is the function you need

    crop image example:

    <?php
    // Create image instances
    $src = imagecreatefromgif('php.gif');
    $dest = imagecreatetruecolor(80, 40);
    
    // Copy
    imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
    
    // Output and free from memory
    header('Content-Type: image/gif');
    imagegif($dest);
    
    imagedestroy($dest);
    imagedestroy($src);
    ?>
    

    if you just need to add a white background imagefill is your function:

    $image = imagecreatetruecolor(100, 100);
    
    // set background to white
    $white = imagecolorallocate($im, 255, 255, 255);
    imagefill($image, 0, 0, $white);