How to implement watermark text and thumbnail image in PHP

Source: Internet
Author: User
Tags imagejpeg
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.