<无详细内容>
-
- /*php Picture Plus text Watermark class Library
- This kind of library temporarily supports only text watermark, the position is the bottom right corner, color random
- Call Method:
- 1, in the need to watermark the top of the file to introduce the class library:
- Include_once ' imageclass.php ';
- 2. Declaring a new class:
- $tpl =new Image_fu;
- 3. Provide parameters for image watermark:
- $TPL->img (image path, watermark text, font path, font size, font angle);
- For example: $tpl->img (' abc.jpg ', ' This is the watermark text ', ' Ziti.ttf ', 30,0)
- */
- Class image_fu{
- Private $image;
- Private $img _info;
- Private $img _width;
- Private $img _height;
- Private $img _im;
- Private $img _text;
- Private $img _ttf= ';
- Private $img _new;
- Private $img _text_size;
- Private $img _JD;
- function img ($img = ', $txt = ', $ttf = ', $size =12, $jiaodu =0) {
- if (Isset ($img) &&file_exists ($img)) {//detect if a picture exists
- $this->image = $img;
- $this->img_text= $txt;
- $this->img_text_size= $size;
- $this->img_jd= $jiaodu;
- if (file_exists ($ttf)) {
- $this->img_ttf= $ttf;
- }else{
- Exit (' Font file: '. $ttf. ' does not exist! ');
- }
- $this->imgyesno ();
- }else{
- Exit (' picture file: '. $img. ' does not exist ');
- }
- }
- Private Function Imgyesno () {
- $this->img_info =getimagesize ($this->image);
- $this->img_width = $this->img_info[0];//picture width
- $this->img_height= $this->img_info[1];//Pictures High
- Detecting picture types
- Switch ($this->img_info[2]) {
- Case 1: $this->img_im = imagecreatefromgif ($this->image);
- Case 2: $this->img_im = imagecreatefromjpeg ($this->image);
- Case 3: $this->img_im = imagecreatefrompng ($this->image);
- Default:exit (' image format does not support Watermark ');
- }
- $this->img_text ();
- }
- Private Function Img_text () {
- Imagealphablending ($this->img_im,true);
- Set color
- $color =imagecolorallocate ($this->img_im,255,255,255);
- $txt _height= $this->img_text_size;
- $txt _jiaodu= $this->img_jd;
- $ttf _im=imagettfbbox ($txt _height, $txt _jiaodu, $this->img_ttf, $this->img_text);
- $w = $ttf _im[2]-$ttf _im[6];
- $h = $ttf _im[3]-$ttf _im[7];
- $w = $ttf _im[7];
- $h = $ttf _im[8];
- unset ($ttf _im);
- $txt _y = $this->img_height*0.5;
- $txt _x = $this->img_width*0.2;
- $txt _y = 0;
- $txt _x = 0;
- $this->img_new= @imagettftext ($this->img_im, $txt _height, $txt _jiaodu, $txt _x, $txt _y, $color, $this->img_ TTF, $this->img_text);
- @unlink ($this->image);//Delete picture
- Switch ($this->img_info[2]) {//Get the format of the background picture
- Case 1:imagegif ($this->img_im, $this->image);
- Case 2:imagejpeg ($this->img_im, $this->image);
- Case 3:imagepng ($this->img_im, $this->image);
- Default:exit (' watermark image failed ');
- }
- }
- Show pictures
- function Img_show () {echo ' image. ' border= ' 0 "alt=" '. $this->img_text. '/> ';}
- Freeing memory
- Private Function img_nothing () {
- unset ($this->img_info);
- Imagedestroy ($this->img_im);
- }
- }
- ?>
Copy Code
- /**
- * Created by JetBrains Phpstorm.
- * User:taoqili
- * date:12-7-18
- * Time: 10:42
- */
- Header ("content-type:text/html; Charset=utf-8 ");
- Error_reporting (E_error | e_warning);
- Include "Uploader.class.php";
- The description form name in the Upload picture box,
- $title = Htmlspecialchars ($_post[' Pictitle '), ent_quotes);
- $path = Htmlspecialchars ($_post[' dir '), ent_quotes);
- Upload Configuration
- $config = Array (
- "Savepath" = ($path = = "1"? "upload/": "upload1/"),
- "MaxSize" = 1000,//per unit KB
- "Allowfiles" = = Array (". gif", ". png", ". jpg", ". jpeg", ". bmp")
- );
- Generate an Upload instance object and complete the upload
- $up = new Uploader ("Upfile", $config);
- /**
- * Get the various parameters of the uploaded file, array structure
- * Array (
- * "Originalname" + "",//Original file name
- * "Name" = "" ",//New file name
- * "url" = "",//Address returned
- * "Size" = "" ",//File size
- * "Type" = "" ",//file type
- * "state" = "" "//upload status, must return" SUCCESS "when upload is successful
- * )
- */
- $info = $up->getfileinfo ();
- /**
- * Return data JSON data to the browser
- * {
- * ' url ': ' a.jpg ',//file path after saving
- * ' title ': ' Hello ',//File description, the front end will be added to the title property on the picture
- * ' original ': ' b.jpg ',//original file name
- * ' state ': ' SUCCESS '//upload status, return SUCCESS on success, any other value will be returned to the picture upload box
- * }
- */
- /* include "imgwater.php";
- $tpl =new Image_fu;
- $tpl->img ($info [' url '], ' http://www.zgxbzh.com/', ' SIMSUN.TTC ', 30,0);
- echo "{' URL ': '". $info ["url"]. "', ' title ': '". $title. "', ' original ': '". $info ["Originalname"]. "', ' state ': '". $info ["state"]. "'}";
Copy Code |