In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to achieve text watermarking and picture watermarking in php. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Text watermarking
Text watermarking is to add text to the picture, mainly using the imagefttext method of the gd library, and requires a font file. The effect picture is as follows:
The implementation code is as follows:
$dst_path = 'dst.jpg'
/ / create an instance of an image
$dst = imagecreatefromstring (file_get_contents ($dst_path))
/ / type in the text
$font ='. / simsun.ttc';// font
$black = imagecolorallocate ($dst, 0x00, 0x00, 0x00); / / font color
Imagefttext ($dst, 13, 0, 20, 20, $black, $font, Happy programming)
/ / output pictures
List ($dst_w, $dst_h, $dst_type) = getimagesize ($dst_path)
Switch ($dst_type) {
Case 1://GIF
Header ('Content-Type: image/gif')
Imagegif ($dst)
Break
Case 2://JPG
Header ('Content-Type: image/jpeg')
Imagejpeg ($dst)
Break
Case 3://PNG
Header ('Content-Type: image/png')
Imagepng ($dst)
Break
Default:
Break
}
Imagedestroy ($dst)
Image watermark
Image watermarking is to add a picture to another picture, mainly using imagecopy and imagecopymerge of the gd library. The effect picture is as follows:
The implementation code is as follows:
$dst_path = 'dst.jpg'
$src_path = 'src.jpg'
/ / create an instance of an image
$dst = imagecreatefromstring (file_get_contents ($dst_path))
$src = imagecreatefromstring (file_get_contents ($src_path))
/ / get the width and height of the watermark image
List ($src_w, $src_h) = getimagesize ($src_path)
/ / copy the watermark image to the target image. The last parameter 50 is to set the transparency. The translucent effect is achieved here.
Imagecopymerge ($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50)
/ / if the watermark image itself has a transparent color, use the imagecopy method
/ / imagecopy ($dst, $src, 10, 10, 0, 0, $src_w, $src_h)
/ / output pictures
List ($dst_w, $dst_h, $dst_type) = getimagesize ($dst_path)
Switch ($dst_type) {
Case 1://GIF
Header ('Content-Type: image/gif')
Imagegif ($dst)
Break
Case 2://JPG
Header ('Content-Type: image/jpeg')
Imagejpeg ($dst)
Break
Case 3://PNG
Header ('Content-Type: image/png')
Imagepng ($dst)
Break
Default:
Break
}
Imagedestroy ($dst)
Imagedestroy ($src)
This is the end of the article on "how to achieve text watermarking and picture watermarking in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.