我想动态创建图像并将其上传到文件夹。我将从用户选择中动态获取身体、袖子、衣领和袖口的图像。我正在合并所有这些图像以创建一个新图像,并将这个新图像上传到一个文件夹中。我无法将文件名上传到文件夹,也没有显示错误,但能够生成合并图像。
下面是代码,
<?php
$body = "img1.jpg";
$sleeve = "img2.jpg";
$collar = "img3.jpg";
$cuff = "img4.jpg";
$outputImage = imagecreatetruecolor(800, 800);
$background = imagecolorallocate($outputImage, 0, 0, 0);
imagecolortransparent($outputImage, $background);
$white = imagecolorallocate($outputImage, 255, 255, 255);
imagefill($outputImage, 0, 0, $white);
$first = imagecreatefrompng($body);
$second = imagecreatefrompng($sleeve);
$third = imagecreatefrompng($collar);
$fourth = imagecreatefrompng($cuff);
imagecopyresized($outputImage,$first,0,0,0,0,600,600,600,600);
imagecopyresized($outputImage,$second,0,0,0,0,600,600,600,600);
imagecopyresized($outputImage,$third,0,0,0,0, 600, 600, 600, 600);
imagecopyresized($outputImage,$fourth,0,0,0,0,600,600,600,600);
$filename = round(microtime(true)).'.png';
imagepng($outputImage, $filename);
define('DIR_IMAGE', '/opt/lampp/htdocs/dutees/image/design-uploads/');
$ret = move_uploaded_file($filename, DIR_IMAGE.$filename);
print_r(error_get_last());
if($ret)
{
echo "success";die;
}
else
{
echo "fail";die;
}
imagedestroy($outputImage);
?>echo "fail";die;
}
imagedestroy($outputImage);
?>