Write a perfect GIF picture in PHP, etc than the Zoom class, with the zoom black background removed
The file type is not judged here, because PNG and JPEG do not have a black background after zooming, so it is not possible to separate GIF.
Checked the information found a perfect solution, accompanied by a detailed ...
Now write things like encapsulation into class ..... Let's call it a bit. I'm not going to tell you how to call.
The effect is as follows:
O_img_file= $oldfile; $this->o_img_width= $width; $this->o_img_height= $height; $this->n_img_file= $newfile; }//proportional scaling and solve the problem of 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; Equal 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 transparent color and determine if in total color if ($trans _init>=0 && $trans _init < Imagecolorstotal ($this->o_img_source)) { If so, search for the RGB hue of this color $trans _index=imagecolorsforindex ($this->o_img_source, $trans _init); Once found, create such a color $trans _new=imagecolorallocate ($this->n_img_source, $trans _index["Red"], $trans _index["green"), $trans _index["Blue"]); Then we use this color to fill in the new Image Imagefill ($this->n_img_source,0,0, $trans _new); Then we set 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, $t His->n_img_height, $this->o_img_width, $this->o_img_height); return $this->n_img_source; }//Final Destroy resource 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 ...