PHP image watermark effect example code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Example code of the PHP image watermark effect. Examples of PHP image watermark effect in LieHuo. Net tutorial :? Php $ backFile: Background Image $ copyFile: image to be copied $ resultFile: Generated file Example code of PHP image watermark effect for helper House (www.Bkjia.com)

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 );

?>

Examples of PHP image watermark effect in LieHuo. Net tutorial :? Php // $ backFile: Background Image // $ copyFile: image to be copied // $ resultFile: generate file...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.