A simple and practical php plus image watermark function

Source: Internet
Author: User

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



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.