The following is a reference fragment:
The following are the referenced contents:
<?php
$backFile: Background map
$copyFile: Images to be copied
$resultFile: Generate File Save address
$copyToX: Copy to the x-coordinate on the background map
$copyToY: Copy to y-coordinate on the background image
$copyToWidth: How wide is the image to be copied
$copyToHeight: How high is the image to be copied
function Imgmerge ($backFile, $copyFile, $resultFile, $copyToX, $copyToY, $copyToWidth, $copyToHeight)
{
Returns "" If the filename suffix is not "PNG"
if (Getfileupperext ($backFile)!= "PNG")
Return "";
Returns "" If the filename suffix is not "PNG"
if (Getfileupperext ($copyFile)!= "PNG")
Return "";
$BACKIMG = Imagecreatefrompng ($backFile);
If the value is not set, returns the
if (!isset ($BACKIMG))
{
Return "";
}
$backImgX = Imagesx ($BACKIMG);
$backImgY = Imagesx ($BACKIMG);
$COPYIMG = Imagecreatefrompng ($copyFile);
If the value is not set, returns the
if (!isset ($COPYIMG))
{
Return "";
}
$COPYRESIZEIMG = Imageresize ($copyImg, $copyToWidth, $copyToHeight);
$bCopy = Imagecopy ($backImg, $COPYRESIZEIMG, $copyToX, $copyToY, 0,0, $copyToWidth, $copyToHeight);
if (! $bCopy)
{
Return "";
}
Imagealphablending ($BACKIMG, true);
Imagesavealpha ($BACKIMG, true);
if (! Imagepng ($BACKIMG, $resultFile))
Return "";
return $resultFile;
}
Get the file name of the incoming file
function Getfileupperext ($fullFile)
{
if (! File_exists ($fullFile))
Return "";
$pathInfo = PathInfo ($fullFile);
return Strtoupper ($pathInfo [' extension ']);
}
function Imageresize ($rImage, $iWidth, $iHeight)
{
$iCanvas = Imagecreate ($iWidth, $iHeight);
$iWidthX = Imagesx ($rImage);
$iHeightY = Imagesy ($rImage);
Imagecopyresampled ($iCanvas, $rImage, 0, 0, 0, 0, $iWidth, $iHeight, $iWidthX, $iHeightY);
return $iCanvas;
}
Imgmerge ("Backimg.png", "Copyimg.png", "Imgmerge.png", 3,3,30,30);
?> |