Reference content is as follows:
// $ BackFile: Background image
// $ CopyFile: image to be copied
// $ ResultFile: address for saving the generated file
// $ CopyToX: X coordinate copied to the background image
// $ CopyToY: Y coordinate copied to the background image
// $ CopyToWidth: change the image to be copied to multiple widths.
// $ CopyToHeight: the height of the image to be copied
Function ImgMerge ($ backFile, $ copyFile, $ resultFile, $ copyToX, $ copyToY, $ copyToWidth, $ copyToHeight)
{
// If the file name suffix is not "PNG", return ""
If (GetFileUpperExt ($ backFile )! = "PNG ")
Return "";
// If the file name suffix is not "PNG", return ""
If (GetFileUpperExt ($ copyFile )! = "PNG ")
Return "";
$ BackImg = ImageCreateFromPng ($ backFile );
// If the value is not set, "" is returned ""
If (! Isset ($ backImg ))
{
Return "";
}
$ BackImgX = ImageSX ($ backImg );
$ BackImgY = ImageSX ($ backImg );
$ CopyImg = ImageCreateFromPng ($ copyFile );
// If the value is not set, "" is returned ""
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 object name
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, $ iWidth, $ iHeight, $ iWidthX, $ iHeightY );
Return $ iCanvas;
}
ImgMerge ("06.png"," 123.png", "07.png", 370,285,150, 15 );
?> |