PHP image text mixed watermark and thumbnail implementation code _php skills

Source: Internet
Author: User
Tags imagecopy imagejpeg mixed
A imagecreatefrom* picture loading function
Pictures for different suffix names
Imagecreatefromgif
Imagecreatefromjpeg
Imagecreatefrompng
Imagecreatefromwbmp
Imagecreatefromstring
Use format: Imagecreatefromgif ("jjj.gif");
Two imagecopy picture merge function
Imagecopy (destimage,simage,int x,int y,int src_x,int src_y,int);
Destimage---original picture (large picture)
Simage---logo picture (small picture)
x---The coordinates of the original picture
Y---
src_x---The coordinates of the logo picture
Src_y---
Src_w---The width of the logo picture
Src_h---The height of the logo picture

Three imagecopyresized picture shearing function
Imagecopyresized (Resource Dst_image,resource src_image,int dst_x,int dst_y,int src_x,int src_y,int dst_w,int dst_h,int Src_w,int src_h);
Dst_image---original true color pictures
Src_image---original picture
Dst_x---From what position is generally 0
Dst_y---is generally 0
Src_x---from where to start shearing is generally 0
Src_y---is generally 0
Dst_w---The width and height of a new picture
Dst_h---
Src_w---The width and height of the original picture
Src_h---

Examples:
image.php
Copy Code code as follows:

<?php
/*
* This PHP file to achieve image watermark and generate thumbnail function
*
*/
This does not write the upload function, first puts the picture to the project root directory
Importing and parsing pictures
$image = "Img.jpg";
$img =getimagesize ($image);
To determine the suffix name of a picture
Switch ($img [2]) {
Case 1:
$im =imagecreatefromgif ($image);
Break
Case 2:
$im =imagecreatefromjpeg ($image);
Break
Case 3:
$im =imagecreatefrompng ($image);
Break
}
Parse picture
$logo = "Pic.jpg";
$pic =getimagesize ($logo);
Switch ($pic [2]) {
Case 1:
$im _pic=imagecreatefromgif ($logo);
Break
Case 2:
$im _pic=imagecreatefromjpeg ($logo);
Break
Case 3:
$im _pic=imagecreatefrompng ($logo);
Break
}
Picture synthesis, also make watermark
Imagecopy ($im, $im _pic,0,500,0,0,100,75);
Set color
$FC =imagecolorallocate ($im, 255,255,255);
First, convert the text to UTF-8 format
$str =iconv ("gb2312", "Utf-8", "Ah-ha");
Add Chinese watermark
Imagettftext ($im, 12,0,20,20, $FC, "Simkai.ttf", "my qq:260954520");
Build a original true color picture
$new _img=imagecreatetruecolor (50,40);
Cut pictures
Imagecopyresized ($new _img, $im, 0,0,0,0,50,40, $img [0], $img [1]);
Output picture
Header ("Content-type:image/jpeg");
Cut the small figure, can be like the following one to generate a small figure with a judgment
Imagejpeg ($new _img);
Create a picture with a watermark
/*
if (imagejpeg ($im, "new picture. jpg")) {
echo "watermark Success";
}
*/
?>

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.