Now write things like encapsulation into class ..... Let's call it a bit. I'm not going to tell you how to call.
Copy the Code code as follows: class resize_image{
Private $o _img_width;//Original image width
Private $o _img_height;//Original image Height
Private $n _img_width;//New image width
Private $n _img_height;//New Image Height
Private $o _img_file;//Original image file
Private $o _img_source;//Original image resources
Private $n _img_file;//New image Resources
Private $n _img_source;//New image Resources
Private $o _to_n_per=0.5;//Image zoom ratio
Initializing internal variables
function __construct ($oldfile, $newfile) {
List ($width, $height) =getimagesize ($oldfile);
$this->o_img_file= $oldfile;
$this->o_img_width= $width;
$this->o_img_height= $height;
$this->n_img_file= $newfile;
}
//proportional scaling and resolving a problem with GIF transparent color black background
Function get_resize_scaling_img () {
$this->n_img_width= $this->o_img_ width* $this->o_to_n_per;
$this->n_img_height= $this->o_img_height* $this->o_to_n_per;
//scale picture (algorithm)
if ($this->n_img_width && ($this->o_img_width < $this->o_img_height))
{
$this->n_img_width = ($this->n_img_height/$this->o_img_height) * $this->o_img_width;
}
Else
{
$this->n_img_height = ($this->n_img_width/$this->o_img_width) * $this->o_img_ Height
}
$this->o_img_source=imagecreatefromgif ($this->o_img_file);
//Create a scaled-size canvas
$this->n_ Img_source=imagecreatetruecolor ($this->o_img_width, $this->n_img_height);
Landscaping: Remove black opaque background
$trans _init=imagecolortransparent ($this->o_img_source);
Look for the transparent color and determine whether it is in the total color
if ($trans _init>=0 && $trans _init < Imagecolorstotal ($this->o_img_source)) {
If it is, search for the RGB hue of this color
$trans _index=imagecolorsforindex ($this->o_img_source, $trans _init);
Create a color after you find it
$trans _new=imagecolorallocate ($this->n_img_source, $trans _index["Red"], $trans _index["green", $trans _index[" Blue "]);
And then we use this color to fill in the new image.
Imagefill ($this->n_img_source,0,0, $trans _new);
And then we're setting the fill color to transparent.
Imagecolortransparent ($this->n_img_source, $trans _new);
}
Copy the original image onto the new artboard
Imagecopyresized ($this->n_img_source, $this->o_img_source,0,0,0,0, $this->n_img_width, $this->n_img_ Height, $this->o_img_width, $this->o_img_height);
return $this->n_img_source;
}
Eventual destruction of resources
function __destruct () {
Imagedestroy ($this->o_img_source);
Imagedestroy ($this->n_img_source);
}
}
Description: Because I didn't think so much before, I declared a lot of private internal variables to call ... The program looks clumsy ...
http://www.bkjia.com/PHPjc/748162.html www.bkjia.com true http://www.bkjia.com/PHPjc/748162.html techarticle now write things like encapsulation into class ..... Let's call it a bit. I'm not going to say how to call the copy code code as follows:? PHP class resize_image{Private $o _img_width;//original image ...