所以,我有一个表单,人们可以通过 AJAX 上传图片。上传图像后,他们可以从包含另一个图像 (.png) 的列表中进行选择,他们可以将其拖放到第一个图像上。
一旦他们对结果感到满意,按下按钮就应该合并两个图像。这工作得很好,即使是位置 - 直到我想有机会调整第二张图片的大小(他们可以拖放到上传的图片上)。
我现在拥有的代码无法调整小图像的大小。事实上,它甚至没有显示在上传的图像(背景图像)上。我在这里想念什么?
//receiving some values from an AJAX call
//those values referes to the background image
$pathToImage = $_POST['pathToImage'];
$posBg = $_POST['posBg'];
$fileUploaded = '../'.$pathToImage;
//those values referes to the image that goes on top of the background
$posTop = $_POST['posTop'];
$posLeft = $_POST['posLeft'];
$itemWidth = $_POST['itemWidth'];
$fileChupon = '../images/chupon1.png';
//my target file
$targetfile = "../images/galeria/testing".time().".png";
//here's the issue.. I am trying to resize the small image that goes on top of the background - this doesn't work and with this piece of code nothing is shown on top of the background
$chuponCreated = imagecreatefrompng($fileChupon);
$newWidth = $itemWidth;
$newHeight = $itemWidth;
$tmp = imagecreatetruecolor($newWidth,$newHeight);
$chupon = imagecopyresampled($tmp, $chuponCreated,0,0,0,0,$newWidth,$newHeight,250,250);
//background image is shown in the dimensions that it's supposed to
$fondo = imagecreatefromjpeg($fileUploaded);
$fondoW = imagesx($fondo);
$fondoH = imagesy($fondo);
$photoFrame = imagecreatetruecolor($fondoW,303);
imagecopyresampled($photoFrame,$fondo,0,$posBg,0,0,$fondoW,$fondoH,$fondoW,$fondoH);
//here trying to add the small image over the background
imagecopy($photoFrame,$chupon,$posLeft,$posTop,0,0,$itemWidth,$itemWidth);
imagejpeg($photoFrame, $targetfile);
$imgPath = $targetfile;
$image = imagecreatefromjpeg($imgPath);
imagejpeg($image);
提前致谢!