For work needs, I wrote a simple PHP image watermarking function.
- /*
- Image watermarking function
- $imag_url is the path to the image to be watermarked
- $str is the string to be added to the picture
- $route is the storage path after watermarking
- */
- function watermark($ imag_url,$str,$route) {
- $type_array=explode(.,$imag_url);
- $imag_type=$type_array[count($type_array)-1];
- switch($imag_type) {
- case gif: $img=imagecreatefromgif($imag_url); break;
- case jpeg: $img=imagecreatefromjpeg($imag_url); break;
- case jpg: $img=imagecreatefromjpeg($imag_url); break;
- case png: $img=imagecreatefrompng($imag_url); break;
- default: $im g= imagecreatefromgif($imag_url); break;
- }
- //Font color
- $gray = imagecolorallocate($img, 235, 235, 235);
- $pink = imagecolorallocate($img, 255, 128, 255);
- /* $fontfile The path of the font, depending on the operating system, can be simhei.ttf (black body), SIMKAI.TTF( Chinese fonts supported by GD*/
- $fontfile = "C:WINDOWSFontsSIMHEI.TTF";
- $str = iconv(GB2312,UTF-8,$str); /*Convert gb2312 character set to UTF-8 characters*/
- imagettftext($img, 30,0, 0, 200, $pink, $fontfile, $str);
- /* Add Chinese watermark*/
- imagepng($img,$route);
- imagedestroy($img);
- }
- ?>
-
I hope the above function can be useful to everyone.
http://www.bkjia.com/PHPjc/486185.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486185.htmlTechArticleFor work needs, I wrote a simple PHP image watermarking function. ?php /* Image watermarking function $imag_url is the path of the image to be watermarked $str is the character to be added to the image...