<? Php
/* ClassName: ImageHandler
* Filename: ImageHandler. phpcls
* Author: Tony Don
* Date: 2008-03-27
* @ Copyright txdnet.com
* Function: Handler Images
*/
Class ImageHandler
{
Var $ dst_img; // target file
Var $ h_src; // image resource handle
Var $ h_dst; // the new graph handle.
Var $ h_mask; // watermark handle
Var $ img_create_quality = 100; // image generation quality
Var $ img_display_quality = 80; // The image quality. The default value is 75.
Var $ img_scale = 0; // scaling ratio of the image
Var $ src_w = 0; // source image width
Var $ src_h = 0; // source image height
Var $ dst_w = 0; // The total width of the new graph.
Var $ dst_h = 0; // total height of the new graph
Var $ fill_w; // fill the image width
Var $ fill_h; // fill Image height
Var $ copy_w; // copy the image width
Var $ copy_h; // copy the image height
Var $ src_x = 0; // The starting abscissa of the source image.
Var $ src_y = 0; // start ordinate of the source image
Var $ start_x; // The starting abscissa of the new graph.
Var $ start_y; // start ordinate of the new graph
Var $ mask_word; // watermark text
Var $ mask_img; // watermark image
Var $ mask_pos_x = 0; // horizontal coordinate of the watermark
Var $ mask_pos_y = 0; // watermark ordinate
Var $ mask_offset_x = 5; // watermark horizontal offset
Var $ mask_offset_y = 5; // watermark vertical offset
Var $ font_w; // watermark font width
Var $ font_h; // watermark font height
Var $ mask_w; // watermark width
Var $ mask_h; // watermark height
Var $ mask_font_color = "#000000"; // watermark text color
Var $ mask_font = 5; // watermark font
Var $ font_size; // size
Var $ mask_position = 0; // Watermark Position
Var $ mask_img_pct = 50; // image merging degree. The larger the value, the lower the merging program.
Var $ mask_txt_pct = 50; // The degree of text merging. The smaller the value, the lower the merging program.
Var $ img_border_size = 0; // image border size
Var $ img_border_color; // image border color
Var $ _ flip_x = 0; // Number of times of horizontal flip
Var $ _ flip_y = 0; // Vertical Flip count
Var $ cut_type = 0; // cut or reduce the type
Var $ img_type; // file type
// Defines the file type and specifies the function of the output image.
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 ImageHandler ()
{
$ This-> mask_font_color = "# ffffff ";
$ This-> font = 2;
$ This-> font_size = 12;
}
/**
* Obtain the image width.
*/
Function getImgWidth ($ src)
{
Return imagesx ($ src );
}
/**
* Obtain the image height.
*/
Function getImgHeight ($ src)
{
Return imagesy ($ src );
}
/**
* Set the image generation path
*
* @ Param string $ src_img image generation path
*/
Function setSrcImg ($ src_img, $ img_type = null)
{
If (! File_exists ($ src_img ))
{
Die ("image does not exist ");
}
If (! Empty ($ 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 (empty ($ src ))
{
Die ("Image 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 the image generation path
*
* @ Param string $ dst_img image 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 image display quality.
*
* @ Param string $ n quality
*/
Function setImgDisplayQuality ($ n)
{
$ This-> img_display_quality = (int) $ n;
}
/**
* Set the image generation quality.
*
* @ Param string $ n quality
*/
Function setImgCreateQuality ($ n)
{
$ This-> img_create_quality = (int) $ n;
}
/**
* Set a 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 the font color.
*
* @ Param string $ color font color
*/
Function setMaskFontColor ($ color = "# ffffff ")
{
$ This-> mask_font_color = $ color;
}
?>