Work needs, write a simple is to use the PHP image and watermark function function.
- /*
- Image plus watermark function
- $imag _url as the path to the image to be watermarked
- $str the string to be added to the picture
- The storage path after $route watermark
- */
- 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: $img =imagecreatefromgif ($imag _url); Break
- }
- Font Color
- $gray = Imagecolorallocate ($img, 235, 235, 235);
- $pink = Imagecolorallocate ($img, 255, 128, 255);
- /* $fontfile the path to the font, depending on the operating system, can be Simhei.ttf (bold), Simkai. TTF (in italics), Simfang. TTF (imitation), SimSun. TTC (Arial & XXFarEastFont-Arial) and other GD-supported Chinese fonts */
- $fontfile = "C:windowsfontssimhei.ttf";
- $str = Iconv (Gb2312,utf-8, $STR); /* Convert the gb2312 character set to UTF-8 characters */
- Imagettftext ($img, 30,0, 0, $pink, $fontfile, $STR);
- /* Add Chinese watermark */
- Imagepng ($img, $route);
- Imagedestroy ($IMG);
- }
- ?>
The above function wants to be able to have a harvest for everyone.
http://www.bkjia.com/PHPjc/486185.html www.bkjia.com true http://www.bkjia.com/PHPjc/486185.html techarticle work needs, write a simple is to use the PHP image and watermark function function. PHP/* Picture watermark function $imag _url is the path to the image to be watermarked $str the character to be added to the picture ...