Search code examples
phpphp-gd

PHP | imagecopymerge() won't work


        $dest = imagecreatefromjpeg('image.jpg');
        $src = imagecreatefrompng('image2.png');

        // Copy and merge
        imagecopymerge($dest, $src, 50, 50, 0, 0, 30, 30, 75);

        imagepng($dest, '1.png');

        imagedestroy($dest);
        imagedestroy($src);

$dest = 50x50
$src = 30x30
1.png only shows the $dest image with out the $src on top of it.

Thanks in advance.


Solution

  • If dest is 50x50, then you're trying to copy from the bottom right corner, which has 50, 50 as coordinates.

     +-----------------------+
     |                       |
     |                       |
     |     you should copy   |
     |                       |
     |                       |
     |                       |
     |     there             |
     |                       |
     |                       |
     |                       |
     |                       |
     +-----------------------+-----------------------+
                             |                       |
                             |                       |
                             |    you're copying     |
                             |                       |
                             |                       |
                             |                       |
                             |                       |
                             |       here            |
                             |                       |
                             |                       |
                             |                       |
                             |                       |
                             +-----------------------+