In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to add image watermark in PHP", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "how to add image watermark in PHP"!
In our daily life, in order not to want their own pictures stolen, often can see in some pictures add watermark, such as our website, input image files will automatically add a watermark in the lower right corner, then this watermark effect is how to achieve it? Through PHP you can achieve the effect of adding watermarks to images.
In the previous article, the operation of cropping an image onto the target image is somewhat similar to adding a watermark. In order to add a watermark, you need to use the imagecopymerge function.
imagecopymerge function
The syntax for the imagecopymerge function is as follows:
imagecopymerge($target image,$source image,$target start x ,$target start y,$source x ,$source y ,$source width,$source height,$transparency)
The transparency value is an integer from 0 to 100, and the larger the transparency value is, the more opaque the watermark is.
Next, let's take a look at how to add a watermark to an image through an example:
First, we prepared an image named test.png and a watermark image named logo.png and put them in our root directory.
Note that the above is an example image, the watermark below is not added by me, it is automatically added by the website, in order to distinguish, the watermark of the example is as follows
Then, the operation is as follows:
Output:
As can be seen from the above results, a watermark with transparency of 50 is added by imagecopymerge function.
Extension of knowledge imagecopy function
Watermarks can be added not only by imagecopy function, but also by imagecopy() function, which can copy part of the function. Its syntax format is as follows:
imagecopy($target image, $source image,$target image x,$target image y,$source image x,$source image y,$source image width,$source image height)
It means that a rectangular area of width w and height h is selected at (x, y) of the source image onto (x,y) of the target image.
Use the imagesx() and imagesy() functions in PHP to get the width and height of the image, respectively. Their syntax is as follows:
imagesx(resource $image)imagesy(resource $image)
Examples are as follows:
Output:
The effects are as follows:
At this point, I believe that we have a deeper understanding of "how to add image watermark in PHP," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.