Two powerful PHP image processing class 1_php skills

Source: Internet
Author: User
Tags abs border color explode imagecopy imagejpeg mkdir
Copy Code code as follows:



<?php


/**


* Basic image processing, to complete the image indentation, watermark add


* When the watermark map exceeds the target picture size, the watermark can be automatically adapted to the target image and reduce


* Watermark Map can be set with the background of the merge degree


*


* Copyright (c) by Ustb99. All rights reserved


*


* To contacts the author write to {@link mailto:ustb80@163.com}


*


* @author Chance


* @version $Id: thumb.class.php,v 1.9 2006/09/30 09:31:56 Zengjian EXP $


* @package System


*/


/**


* Thumbhandler


* @access Public


*/


/*


How to use:


Automatic Trimming:


The program will trim the largest square from the middle by the size of the picture and make the thumbnail by target size.


$t->setsrcimg ("img/test.jpg");


$t->setcuttype (1);//This sentence is OK.


$t->setdstimg ("tmp/new_test.jpg");


$t->createimg (60,60);


Manual trimming:


The program takes the map from the source diagram at the specified location


$t->setsrcimg ("img/test.jpg");


$t->setcuttype (2);//indicate manual trimming


$t->setsrccutposition (100, 100);//source diagram start coordinates


$t->setrectanglecut (300, 200);//Cut size


$t->setdstimg ("tmp/new_test.jpg");


$t->createimg (300,200);


*/


Class Thumbhandler


{


var $dst _img;//target file


var $h _src; Picture resource handle


var $h _dst;//New Graph handle


var $h _mask;//Watermark Handle


var $img _create_quality = 100;//picture Generation quality


var $img _display_quality = 80;//picture display quality, defaults to 75


var $img _scale = 0;//picture Scaling


var $src _w = 0;//artwork Width


var $src _h = 0;//original height


var $dst _w = 0;//total width of new graphs


var $dst _h = 0;//new Diagram Total height


var $fill _w;//padding graphic width


var $fill _h;//fill Graphic height


var $copy _w;//Copy Graphics width


var $copy _h;//Copy Graphics high


var $src _x = 0;//Original drawing starting Horizontal


var $src _y = 0;//Original mapping start ordinate


A new graph of Var $start _x;//to draw the starting horizontal axis


A new graph of Var $start _y;//to draw the starting ordinate


var $mask _word;//Watermark Text


var $mask _img;//Watermark Picture


var $mask _pos_x = 0;//Watermark Horizontal


var $mask _pos_y = 0;//Watermark Ordinate


var $mask _offset_x = 5;//watermark Lateral offset


var $mask _offset_y = 5;//watermark longitudinal offset


var $font _w;//Watermark Font Width


var $font _h;//watermark Font Height


var $mask _w;//Watermark Width


var $mask _h;//Watermark High


var $mask _font_color = "#ffffff";//Watermark text color


var $mask _font = 2;//Watermark Font


var $font _size;//Dimensions


var $mask _position = 0;//Watermark Location


var $mask _img_pct = 50;//picture Merge degree, the greater the value, the lower the merge program


var $mask _txt_pct = 50;//text merge, the smaller the value, the lower the merge program


var $img _border_size = 0;//picture Border dimensions


var $img _border_color;//picture Border color


var $_flip_x=0;//horizontal Flip Times


var $_flip_y=0;//vertical Flip Times


var $cut _type=0;//Cut Type


var $img _type;//File type


File type definition, and indicates the function of the output picture


var $all _type = Array (


"JPG" => array ("Output" => "imagejpeg"),


"GIF" => Array ("Output" => "Imagegif"),


"PNG" => Array ("Output" => "Imagepng"),


"Wbmp" => Array ("Output" => "Image2wbmp"),


"JPEG" => Array ("Output" => "imagejpeg"));


/**


* Constructor


*/


function Thumbhandler ()


{


$this->mask_font_color = "#ffffff";


$this->font = 2;


$this->font_size = 12;


}


/**


* Get the width of the picture


*/


function Getimgwidth ($SRC)


{


Return Imagesx ($SRC);


}


/**


* Get a high picture


*/


function Getimgheight ($SRC)


{


Return Imagesy ($SRC);


}


/**


* Set Picture Generation path


*


* @param string $src _img picture Generation Path


*/


function setsrcimg ($src _img, $img _type=null)


{


if (!file_exists ($src _img))


{


Die ("Picture does not exist");


}


if (!emptyempty ($img _type))


{


$this->img_type = $img _type;


}


Else


{


$this->img_type = $this->_getimgtype ($src _img);


}


$this->_checkvalid ($this->img_type);


file_get_contents function requires PHP version >4.3.0


$SRC = ';


if (function_exists ("file_get_contents"))


{


$SRC = file_get_contents ($src _img);


}


Else


{


$handle = fopen ($src _img, "R");


while (!feof ($handle))


{


$src. = Fgets ($FD, 4096);


}


Fclose ($handle);


}


if (Emptyempty ($SRC))


{


Die ("Picture source is empty");


}


$this->h_src = @ImageCreateFromString ($SRC);


$this->src_w = $this->getimgwidth ($this->h_src);


$this->src_h = $this->getimgheight ($this->h_src);


}


/**


* Set Picture Generation path


*


* @param string $dst _img picture Generation Path


*/


function setdstimg ($DST _img)


{


$arr = explode ('/', $dst _img);


$last = Array_pop ($arr);


$path = implode ('/', $arr);


$this->_mkdirs ($path);


$this->dst_img = $dst _img;


}


/**


* Set the display quality of the picture


*


* @param string $n quality


*/


function Setimgdisplayquality ($n)


{


$this->img_display_quality = (int) $n;


}


/**


* Set the build quality of the picture


*


* @param string $n quality


*/


function Setimgcreatequality ($n)


{


$this->img_create_quality = (int) $n;


}


/**


* Set Text watermark


*


* @param string $word watermark Text


* @param integer $font watermark Font


* @param string $color watermark Font Color


*/


function Setmaskword ($word)


{


$this->mask_word. = $word;


}


/**


* Set Font Color


*


* @param string $color font Color


*/


function Setmaskfontcolor ($color = "#ffffff")


{


$this->mask_font_color = $color;


}


/**


* Set Watermark Font


*


* @param string|integer $font fonts


*/


function Setmaskfont ($font =2)


{


if (!is_numeric ($font) &&!file_exists ($font))


{


Die ("Font file does not exist");


}


$this->font = $font;


}


/**


* Set text font size, only valid for TrueType fonts


*/


function setmaskfontsize ($size = "12")


{


$this->font_size = $size;


}


/**


* Set Picture watermark


*


* @param string $img watermark picture Source


*/


function Setmaskimg ($img)


{


$this->mask_img = $img;


}


/**


* Set Watermark Horizontal Offset


*


* @param integer $x horizontal offset


*/


function Setmaskoffsetx ($x)


{


$this->mask_offset_x = (int) $x;


}


/**


* Set Watermark Vertical Offset


*


* @param integer $y longitudinal offset


*/


function Setmaskoffsety ($y)


{


$this->mask_offset_y = (int) $y;


}


/**


* Specify watermark Location


*


* @param integer $position position, 1: Upper left, 2: Lower left, 3: Upper right, 0/4: lower right


*/


function setmaskposition ($position =0)


{


$this->mask_position = (int) $position;


}


/**


* Set Picture Merge degree


*


* @param integer $n degree of consolidation


*/


function setmaskimgpct ($n)


{


$this->mask_img_pct = (int) $n;


}


/**


* Set the degree of text merge


*


* @param integer $n degree of consolidation


*/


function setmasktxtpct ($n)


{


$this->mask_txt_pct = (int) $n;


}


/**


* Set thumbnail border


*


* @param (type) (parameter name) (description)


*/


function Setdstimgborder ($size =1, $color = "#000000")


{


$this->img_border_size = (int) $size;


$this->img_border_color = $color;


}


/**


* Flip Horizontally


*/


function Fliph ()


{


$this->_flip_x++;


}


/**


* Flip Vertically


*/


function FLIPV ()


{


$this->_flip_y++;


}


/**


* Set the Cut type


*


* @param (type) (parameter name) (description)


*/


function Setcuttype ($type)


{


$this->cut_type = (int) $type;


}


/**


* Set Picture Cut


*


* @param integer $width rectangular Shearing


*/


function Setrectanglecut ($width, $height)


{


$this->fill_w = (int) $width;


$this->fill_h = (int) $height;


}


/**


* Set the source diagram to cut the starting coordinate point


*


* @param (type) (parameter name) (description)


*/


function Setsrccutposition ($x, $y)


{


$this->src_x = (int) $x;


$this->src_y = (int) $y;


}


/**


* Create picture, main function


* @param integer $a this parameter is used as a percentage when the second parameter is missing.


* Otherwise as width value


* @param integer $b The height of the picture after scaling


*/


function createimg ($a, $b =null)


{


$num = Func_num_args ();


if (1 = $num)


{


$r = (int) $a;


if ($r < 1)


{


Die ("Picture scaling must not be less than 1");


}


$this->img_scale = $r;


$this->_setnewimgsize ($R);


}


if (2 = $num)


{


$w = (int) $a;


$h = (int) $b;


if (0 = $w)


{


Die ("target width cannot be 0");


}


if (0 = $h)


{


Die ("target height cannot be 0");


}


$this->_setnewimgsize ($w, $h);


}


if ($this->_flip_x%2!=0)


{


$this->_fliph ($this->h_src);


}


if ($this->_flip_y%2!=0)


{


$this->_FLIPV ($this->h_src);


}


$this->_createmask ();


$this->_output ();


Release


if (Imagedestroy ($this->h_src) && Imagedestroy ($this->h_dst))


{


return true;


}


Else


{


return false;


}


}


/**


* Generate watermark, call to generate watermark text and watermark picture two methods


*/


function _createmask ()


{


if ($this->mask_word)


{


Get font information


$this->_setfontinfo ();


if ($this->_isfull ())


{


Die ("Watermark text too large");


}


Else


{


$this->H_DST = Imagecreatetruecolor ($this->dst_w, $this->dst_h);


$white = Imagecolorallocate ($this->h_dst,255,255,255);


Imagefilledrectangle ($this->h_dst,0,0, $this->dst_w, $this->dst_h, $white);/Fill Background color


$this->_drawborder ();


Imagecopyresampled ($this->h_dst, $this->h_src,


$this->start_x, $this->start_y,


$this->src_x, $this->src_y,


$this->fill_w, $this->fill_h,


$this->copy_w, $this->copy_h);


$this->_createmaskword ($this->h_dst);


}


}


if ($this->mask_img)


{


$this->_loadmaskimg () ()////when loading, achieve wide height


if ($this->_isfull ())


{


The watermark is generated on the original artwork and then copied


$this->_createmaskimg ($this->h_src);


$this->H_DST = Imagecreatetruecolor ($this->dst_w, $this->dst_h);


$white = Imagecolorallocate ($this->h_dst,255,255,255);


Imagefilledrectangle ($this->h_dst,0,0, $this->dst_w, $this->dst_h, $white);/Fill Background color


$this->_drawborder ();


Imagecopyresampled ($this->h_dst, $this->h_src,


$this->start_x, $this->start_y,


$this->src_x, $this->src_y,


$this->fill_w, $this->start_y,


$this->copy_w, $this->copy_h);


}


Else


{


Create a new diagram and copy it


$this->H_DST = Imagecreatetruecolor ($this->dst_w, $this->dst_h);


$white = Imagecolorallocate ($this->h_dst,255,255,255);


Imagefilledrectangle ($this->h_dst,0,0, $this->dst_w, $this->dst_h, $white);/Fill Background color


$this->_drawborder ();


Imagecopyresampled ($this->h_dst, $this->h_src,


$this->start_x, $this->start_y,


$this->src_x, $this->src_y,


$this->fill_w, $this->fill_h,


$this->copy_w, $this->copy_h);


$this->_createmaskimg ($this->h_dst);


}


}


if (Emptyempty ($this->mask_word) && emptyempty ($this->mask_img))


{


$this->H_DST = Imagecreatetruecolor ($this->dst_w, $this->dst_h);


$white = Imagecolorallocate ($this->h_dst,255,255,255);


Imagefilledrectangle ($this->h_dst,0,0, $this->dst_w, $this->dst_h, $white);/Fill Background color


$this->_drawborder ();


Imagecopyresampled ($this->h_dst, $this->h_src,


$this->start_x, $this->start_y,


$this->src_x, $this->src_y,


$this->fill_w, $this->fill_h,


$this->copy_w, $this->copy_h);


}


}


/**


* Draw a border


*/


function _drawborder ()


{


if (!emptyempty ($this->img_border_size))


{


$c = $this->_parsecolor ($this->img_border_color);


$color = Imagecolorallocate ($this->h_src, $c [0], $c [1], $c [2]);


Imagefilledrectangle ($this->h_dst,0,0, $this->dst_w, $this->dst_h, $color);/Fill Background color


}


}


/**


* Generate watermark Text


*/


function _createmaskword ($SRC)


{


$this->_countmaskpos ();


$this->_checkmaskvalid ();


$c = $this->_parsecolor ($this->mask_font_color);


$color = Imagecolorallocatealpha ($src, $c [0], $c [1], $c [2], $this->mask_txt_pct);


if (Is_numeric ($this->font))


{


Imagestring ($SRC,


$this->font,


$this->mask_pos_x, $this->mask_pos_y,


$this->mask_word,


$color);


}


Else


{


Imagettftext ($SRC,


$this->font_size, 0,


$this->mask_pos_x, $this->mask_pos_y,


$color,


$this->font,


$this->mask_word);


}


}


/**


* Generate a watermark map


*/


function _createmaskimg ($SRC)


{


$this->_countmaskpos ();


$this->_checkmaskvalid ();


Imagecopymerge ($SRC,


$this->h_mask,


$this->mask_pos_x, $this->mask_pos_y,


0, 0,


$this->mask_w, $this->mask_h,


$this->mask_img_pct);


Imagedestroy ($this->h_mask);


}


/**


* Load Watermark Map


*/


function _loadmaskimg ()


{


$mask _type = $this->_getimgtype ($this->mask_img);


$this->_checkvalid ($mask _type);


file_get_contents function requires PHP version >4.3.0


$SRC = ';


if (function_exists ("file_get_contents"))


{


$SRC = file_get_contents ($this->mask_img);


}


Else


{


$handle = fopen ($this->mask_img, "R");


while (!feof ($handle))


{


$src. = Fgets ($FD, 4096);


}


Fclose ($handle);


}


if (Emptyempty ($this->mask_img))


{


Die ("Watermark picture is empty");


}


$this->h_mask = imagecreatefromstring ($SRC);


$this->mask_w = $this->getimgwidth ($this->h_mask);


$this->mask_h = $this->getimgheight ($this->h_mask);


}


/**


* Picture Output


*/


function _output ()


{


$img _type = $this->img_type;


$func _name = $this->all_type[$img _type][' output ');


if (function_exists ($func _name))


{


Judge the browser, if IE does not send headers


if (Isset ($_server[' http_user_agent '))


{


$ua = Strtoupper ($_server[' http_user_agent '));


if (!preg_match ('/^.*msie.*\) $/i ', $ua))


{


Header ("Content-type: $img _type");


}


}


$func _name ($this->h_dst, $this->dst_img, $this->img_display_quality);


}


Else


{


return false;


}


}


/**


* Color Analysis


*


* @param string $color hexadecimal color


*/


function _parsecolor ($color)


{


$arr = Array ();


for ($ii =1; $ii <strlen ($color); $ii + +)


{


$arr [] = Hexdec (substr ($color, $ii, 2));


$ii + +;


}


return $arr;


}


/**


* Calculate the position coordinates


*/


function _countmaskpos ()


{


if ($this->_isfull ())


{


Switch ($this->mask_position)


{


Case 1:


Top left


$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;


$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;


Break


Case 2:


Lower left


$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;


$this->mask_pos_y = $this->src_h-$this->mask_h-$this->mask_offset_y;


Break


Case 3:


Top Right


$this->mask_pos_x = $this->src_w-$this->mask_w-$this->mask_offset_x;


$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;


Break


Case 4:


Lower right


$this->mask_pos_x = $this->src_w-$this->mask_w-$this->mask_offset_x;


$this->mask_pos_y = $this->src_h-$this->mask_h-$this->mask_offset_y;


Break


Default


By default, the watermark is placed to the lower right, offset the specified pixel


$this->mask_pos_x = $this->src_w-$this->mask_w-$this->mask_offset_x;


$this->mask_pos_y = $this->src_h-$this->mask_h-$this->mask_offset_y;


Break


}


}


Else


{


Switch ($this->mask_position)


{


Case 1:


Top left


$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;


$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;


Break


Case 2:


Lower left


$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;


$this->mask_pos_y = $this->dst_h-$this->mask_h-$this->mask_offset_y-$this->img_border_size;


Break


Case 3:


Top Right


$this->mask_pos_x = $this->dst_w-$this->mask_w-$this->mask_offset_x-$this->img_border_size;


$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;


Break


Case 4:


Lower right


$this->mask_pos_x = $this->dst_w-$this->mask_w-$this->mask_offset_x-$this->img_border_size;


$this->mask_pos_y = $this->dst_h-$this->mask_h-$this->mask_offset_y-$this->img_border_size;


Break


Default


By default, the watermark is placed to the lower right, offset the specified pixel


$this->mask_pos_x = $this->dst_w-$this->mask_w-$this->mask_offset_x-$this->img_border_size;


$this->mask_pos_y = $this->dst_h-$this->mask_h-$this->mask_offset_y-$this->img_border_size;


Break


}


}


}


/**


* Set Font information


*/


function _setfontinfo ()


{


if (Is_numeric ($this->font))


{


$this->font_w = imagefontwidth ($this->font);


$this->font_h = imagefontheight ($this->font);


Calculate the width of watermark font height


$word _length = strlen ($this->mask_word);


$this->mask_w = $this->font_w* $word _length;


$this->mask_h = $this->font_h;


}


Else


{


$arr = Imagettfbbox ($this->font_size,0, $this->font, $this->mask_word);


$this->mask_w = ABS ($arr [0]-$arr [2]);


$this->mask_h = ABS ($arr [7]-$arr [1]);


}


}


/**


* Set the new diagram size


*


* @param integer $img _w target width


* @param integer $img _h target height


*/


function _setnewimgsize ($img _w, $img _h=null)


{


$num = Func_num_args ();


if (1 = $num)


{


$this->img_scale = $img _w;//width as a proportion


$this->fill_w = Round ($this->src_w * $this->img_scale/100)-$this->img_border_size*2;


$this->fill_h = Round ($this->src_h * $this->img_scale/100)-$this->img_border_size*2;


Source file Start coordinates


$this->src_x = 0;


$this->src_y = 0;


$this->copy_w = $this->src_w;


$this->copy_h = $this->src_h;


Target size


$this->dst_w = $this->fill_w + $this->img_border_size*2;


$this->dst_h = $this->fill_h + $this->img_border_size*2;


}


if (2 = $num)


{


$fill _w = (int) $img _w-$this->img_border_size*2;


$fill _h = (int) $img _h-$this->img_border_size*2;


if ($fill _w < 0 | | $fill _h < 0)


{


Die ("The picture border is too large to exceed the width of the picture");


}


$rate _w = $this->src_w/$fill _w;


$rate _h = $this->src_h/$fill _h;


Switch ($this->cut_type)


{


Case 0:


If the artwork is larger than the thumbnail, it shrinks, otherwise it doesn't shrink.


if ($rate _w < 1 && $rate _h < 1)


{


$this->fill_w = (int) $this->src_w;


$this->fill_h = (int) $this->src_h;


}


Else


{


if ($rate _w >= $rate _h)


{


$this->fill_w = (int) $fill _w;


$this->fill_h = round ($this->src_h/$rate _w);


}


Else


{


$this->fill_w = round ($this->src_w/$rate _h);


$this->fill_h = (int) $fill _h;


}


}


$this->src_x = 0;


$this->src_y = 0;


$this->copy_w = $this->src_w;


$this->copy_h = $this->src_h;


Target size


$this->dst_w = $this->fill_w + $this->img_border_size*2;


$this->dst_h = $this->fill_h + $this->img_border_size*2;


Break


Automatic Trimming


Case 1:


If the picture is to shrink the cut before you operate


if ($rate _w >= 1 && $rate _h >=1)


{


if ($this->src_w > $this->src_h)


{


$src _x = round ($this->src_w-$this->src_h)/2;


$this->setsrccutposition ($src _x, 0);


$this->setrectanglecut ($fill _h, $fill _h);


$this->copy_w = $this->src_h;


$this->copy_h = $this->src_h;


}


ElseIf ($this->src_w < $this->src_h)


{


$src _y = round ($this->src_h-$this->src_w)/2;


$this->setsrccutposition (0, $src _y);


$this->setrectanglecut ($fill _w, $fill _h);


$this->copy_w = $this->src_w;


$this->copy_h = $this->src_w;


}


Else


{


$this->setsrccutposition (0, 0);


$this->copy_w = $this->src_w;


$this->copy_h = $this->src_w;


$this->setrectanglecut ($fill _w, $fill _h);


}


}


Else


{


$this->setsrccutposition (0, 0);


$this->setrectanglecut ($this->src_w, $this->src_h);


$this->copy_w = $this->src_w;


$this->copy_h = $this->src_h;


}


Target size


$this->dst_w = $this->fill_w + $this->img_border_size*2;


$this->dst_h = $this->fill_h + $this->img_border_size*2;


Break


Hand cut


Case 2:


$this->copy_w = $this->fill_w;


$this->copy_h = $this->fill_h;


Target size


$this->dst_w = $this->fill_w + $this->img_border_size*2;


$this->dst_h = $this->fill_h + $this->img_border_size*2;


Break


Default


Break


}


}


Target file Start coordinates


$this->start_x = $this->img_border_size;


$this->start_y = $this->img_border_size;


}


/**


* Check whether the watermark is larger than the resulting picture width


*/


function _isfull ()


{


Return ($this->mask_w + $this->mask_offset_x > $this->fill_w


|| $this->mask_h + $this->mask_offset_y > $this->fill_h)


? true:false;


}


/**


* Check whether the watermark is larger than the original image


*/


function _checkmaskvalid ()


{


if ($this->mask_w + $this->mask_offset_x > $this->src_w


|| $this->mask_h + $this->mask_offset_y > $this->src_h)


{


Die ("watermark picture size larger than the original image, please reduce the watermark map");


}


}


/**


* Get Picture type


*


* @param string $file _path file path


*/


function _getimgtype ($file _path)


{


$type _list = Array ("1" => "gif", "2" => "jpg", "3" => "PNG", "4" => "SWF", "5" => "PSD", "6" => "BMP", "" "=> "Wbmp");


if (file_exists ($file _path))


{


$img _info = @getimagesize ($file _path);


if (Isset ($type _list[$img _info[2]))


{


return $type _list[$img _info[2]];


}


}


Else


{


Die ("file does not exist, cannot get file type!");


}


}


/**


* Check the picture type is legitimate, call the Array_key_exists function, this function requires


* PHP version is larger than 4.1.0


*


* @param string $img _type file type


*/


function _checkvalid ($img _type)


{


if (!array_key_exists ($img _type, $this->all_type))


{


return false;


}


}


/**


* Generate directory by specified path


*


* @param string $path path


*/


function _mkdirs ($path)


{


$adir = explode ('/', $path);


$dirlist = ';


$rootdir = Array_shift ($adir);


if ($rootdir!= '. ') $rootdir!= ' ... ') &&!file_exists ($rootdir))


{


@mkdir ($rootdir);


}


foreach ($adir as $key => $val)


{


if ($val!= '. ') && $val!= ' ... ')


{


$dirlist. = "/". $val;


$dirpath = $rootdir. $dirlist;


if (!file_exists ($dirpath))


{


@mkdir ($dirpath);


@chmod ($dirpath, 0777);


}


}


}


}


/**


* Flip Vertically


*


* @param string $src picture source


*/


function _FLIPV ($SRC)


{


$src _x = $this->getimgwidth ($SRC);


$src _y = $this->getimgheight ($SRC);


$new _im = Imagecreatetruecolor ($src _x, $src _y);


for ($y = 0; $y < $src _y; $y + +)


{


Imagecopy ($new _im, $src, 0, $src _y-$y-1, 0, $y, $src _x, 1);


}


$this->h_src = $new _im;


}


/**


* Flip Horizontally


*


* @param string $src picture source


*/


function _fliph ($SRC)


{


$src _x = $this->getimgwidth ($SRC);


$src _y = $this->getimgheight ($SRC);


$new _im = Imagecreatetruecolor ($src _x, $src _y);


for ($x = 0; $x < $src _x; $x + +)


{


Imagecopy ($new _im, $src, $src _x-$x-1, 0, $x, 0, 1, $src _y);


}


$this->h_src = $new _im;


}


}


Use instance:


< PHP


Require_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


$t->setsrcimg ("img/test.jpg");


$t->setdstimg ("tmp/new_test.jpg");


$t->setmaskimg ("Img/test.gif");


$t->setmaskposition (1);


$t->setmaskimgpct (80);


$t->setdstimgborder (4, "#dddddd");


Specify zoom proportions


$t->createimg (300,200);


?>


<?php


Require_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


Basic use


$t->setsrcimg ("img/test.jpg");


$t->setmaskword ("test");


$t->setdstimgborder ("#dddddd");


Specify zoom proportions


$t->createimg (50);


?>


<?php


Equire_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


Basic use


$t->setsrcimg ("img/test.jpg");


$t->setmaskword ("test");


Specify Fixed width height


$t->createimg (200,200);


?>


<?php


Require_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


$t->setsrcimg ("img/test.jpg");


$t->setdstimg ("tmp/new_test.jpg");


$t->setmaskword ("test");


Specify Fixed width height


$t->createimg (200,200);


?>


<?php


Require_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


$t->setsrcimg ("img/test.jpg");


Specify font file Address


$t->setmaskfont ("C:/winnt/fonts/arial.ttf");


$t->setmaskfontsize (20);


$t->setmaskfontcolor ("#ffff00");


$t->setmaskword ("test3333333");


$t->setdstimgborder ("#dddddd");


$t->createimg (50);


?>


<?php


Require_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


$t->setsrcimg ("img/test.jpg");


$t->setmaskoffsetx (55);


$t->setmaskoffsety (55);


$t->setmaskposition (1);


$t->setmaskposition (2);


$t->setmaskposition (3);


$t->setmaskposition (4);


$t->setmaskfontcolor ("#ffff00");


$t->setmaskword ("test");


Specify Fixed width height


$t->createimg (50);


?>


<?php


Require_once (' lib/thumb.class.php ');


$t = new Thumbhandler ();


$t->setsrcimg ("img/test.jpg");


$t->setmaskfont ("C:/winnt/fonts/simyou.ttf");


$t->setmaskfontsize (20);


$t->setmaskfontcolor ("#ffffff");


$t->setmasktxtpct (20);


$t->setdstimgborder ("#dddddd");


$text = "Chinese";


$str = mb_convert_encoding ($text, "UTF-8", "gb2312");


$t->setmaskword ($STR);


$t->setmaskword ("test");


Specify Fixed width height


$t->createimg (50);


?>


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.