This article mainly introduces PHP implementation of the watermark text and thumbnail image method, combined with a complete example of PHP to implement the watermark text added and thumbnail generation of the relevant steps and operation skills, the need for friends can refer to the next
Specific as follows:
<?php $im = ' xiatian.jpg '; $im 2 = ' winter3.jpg '; $img = GetImage ($im); $bimg = GetImage ($im 2); $image = getimagesize ($im); Print_r ($image); Array ([0] = width/*[1] [2] = 3 picture Type [3] = width= "height=" [bits] =& Gt 8 [MIME] + image/png) *//Image Copy combination------$bimg----imagecopy ($bimg, $img, 4, 0, 0, getwidth ($im), GetHeight ($im) ); Watermark Text $color = imagecolorallocate ($bimg, 255, 255, 0); $STR = "China"; $str = mb_convert_encoding ($str, "html-entities", "utf-8"); Imagettftext ($bimg, 0, Rand (20,getwidth ($im 2) -100), Rand (40,getheight ($im 2)), $color, ' Msyh. TTF ', $str); Cut, regenerate thumbnails $new = Imagecreatetruecolor (50, 50); Imagecopyresized ($new, $bimg, 0, 0, 0, 0, ($im 2), GetHeight ($im 2)); Output to the browser header ("Content-type:image/jpeg"); If the PNG image is also displayed correctly, the browser is responsible for correctly parsing the imagejpeg ($new); Generate large image, small figure imagejpeg ($new, ' small.jpg '); Imagejpeg ($bimg, ' big.jpg '); function GetImage ($img _file) {$image = GetImagesIze ($img _file); Judging is the kind of picture type switch ($image [2]) {Case 1: $img = @imagecreatefromgif ($img _file); Break Case 2: $img = @imagecreatefromjpeg ($img _file); Break Case 3: $img = @imagecreatefrompng ($img _file); Break } return $img; } function GetWidth ($img _file) {$image = getimagesize ($img _file); return $image [0]; } function GetHeight ($img _file) {$image = getimagesize ($img _file); return $image [1]; }?>
The above is the whole content of this article, I hope that everyone's study has helped.