Using PHP GD library text image watermark thumbnail

Source: Internet
Author: User

One: Add text watermark using method

Require ' image.class.php '
$SRC = "001.jpg";
$content = "Hello";
$font _url= "My.ttf";
$size = 20;
$image =new image ($SRC);
$color =array (
0=>255,
1=>255,
2=>255,
2=>20
);
$local =array (
' X ' =>20,
' Y ' =>30
);
$angle = 10;
$image->fontmark ($content, $font _url, $size, $color, $local, $angle);
$image->show ();


Two: Picture thumbnail use method:


Require ' image.class.php '
$SRC = "001.jpg";
$image =new image ($SRC);
$image->thumb (300,200);
$image->show ();


Three: image.class.php

Class image{
Private $info;
Private $image;
Public Function __contruct ($SRC) {
$info = getimagesize ($SRC);
$this->info=array (
' Width ' => $info [0],
' Height ' => $info [1],
' Type ' =>image_type_to_extension ($info [2],false),
' MIME ' => $info [' MIME '],

);
$fun = "imagecreatefrom{$this->info[' type ']}";

$this->image= $fun ($SRC);

}

Thumbnail image
Public Function THUMD ($width, $height) {
$image _thumb= Imagecreatetruecolor ($width, $height);
Imagecopyresampled ($image _thumb, $this->image,0,0,0,0, $width, $height, $this->info[' width '], $this->info[ ' Height ']);
Imagedestroy ($this->image);
$this->image= $image _thumb;

}
Text watermark
Public Function Fontmark ($content, $font _url, $size, $color, $local, $angle) {

$col =imagecolorallocatealpha ($this->image, $color [0], $color [1], $color [2], $color [3]);
$text =imagettftext ($this->image, $size, $angle, $local [' X '], $local [' Y '], $col, $font _url, $content);
}
Output picture
Public Function Show ()
{
Header ("Content-type:", $this->info[' mime '));

$func = "image{$this->info[' type ']}";
$func ($this->image);

}
Public function Save ($nwename) {
$func = "image{$this->info[' type ']}";
Remove picture display from memory
$func ($this->image);
Save picture
$func ($this->image, $nwename. $this->info[' type ']);

}
Public Function _destruct () {

Imagedestroy ($this->image);
}

}

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.