【发布时间】:2020-11-05 06:48:57
【问题描述】:
我想把$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);
我得到的结果是这样的:
如您所见,青色正在影响原始图像:
关于我错了什么的任何想法?谢谢!
【问题讨论】: