我想将 $original 图像粘贴到 $fondo 图像的中心,我编写以下代码:
<?php
header('Content-Type: image/png');
// The file
$fondo = imagecreate(1000,1000); // Create 1000x1000 image
$color_fondo = imagecolorallocate($fondo,197,237,206); // Set color of background
$original = imagecreatefromstring(file_get_contents('test.jpg')); // Load image
$wb = imagesx($fondo); // Bakground width
$wi = imagesx($original); // Image width
$hb = imagesy($fondo);
$hi = imagesy($original);
//Want to center in the middle of the image, so calc ($wb/2-$wi/2)
imagecopy($fondo,$original,($wb/2-$wi/2),($hb/2-$hi/2),0,0,imagesx($original),imagesy($original));
imagepng($fondo);
我得到的结果是这样的:
正如您所看到的,青色正在影响原始图像:
关于我错了什么有什么想法吗?谢谢你!