<?/* image Processing class: Thumbnail, crop, fillet, tilt */class resizeimage{ //picture type var $type; //actual width var $width; //actual height var $height //Change width var $resize _width; //the height of the change var $resize _height; //whether to crop the map var $ cut; //source Images var $srcimg; //Target image Address var $dstimg; //fillet source var $corner; var $im; Function resizeimage ($img, $corner, $wid, $hei, $c, $corner _radius, $angle) { $this->srcimg = $img; $this->corner = $corner; $thisresize_width = $wid; $this->resize_height = $ hei; $this->cut = $c; $this->corner_radius = $corner _radius; $this->angle = $angle; Types of //pictures $this->type = substr (STRRCHR ($ This->srcimg, "."), 1); //initialization Image $this->initi_img (); //Target image Address $this -> dst_img (); //-- $this->width = imagesx ($this->im); $this->height = imagesy ($this->im); //Generating Image $this->newimg (); imagedestroy ($this->im); } function newimg () { //ratio of Altered Images $resize _ratio = ($this->resize_ width)/($this->resize_height); //ratio of actual images $ratio = ($this->width)/($this->height); if (($this->cut) = = "1") //drawing { if ($ratio >= $resize _ratio) //High Priority { $newimg = Imagecreatetruecolor ($this->resize_width, $this->resize_height); imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, ($this->height) * $resize _ratio), $this->height); $tmp = $this- >rounded_corner ($newimg, $this->resize_width); imagepng ($tmp, $this->dstimg); } if ($ratio < $resize _ratio) //Width Priority { $ Newimg = imagecreatetruecolor ($this->resize_width, $this->resize_height); imagecopyresampled ($newimg, $ this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $ this->width, (($this->width)/$resize _ratio)); $ tmp = $this->rounded_corner ($newimg); imagepng ($tmp, $this->dstimg); &nbSP;} } else //No drawing { if ($ratio >= $resize _ratio) { $ Newimg = imagecreatetruecolor ($this->resize_width, ($this->resize_width)/$ratio); imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width) /$ratio, $this->width, $this->height); ImageJpeg ($newimg, $this->dstimg); &nBsp; } if ($ratio < $resize _ratio) { $newimg = imagecreatetruecolor ($this->resize_height) *$ Ratio, $this->resize_height); imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, ($this Resize_height) * $ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg, $this- >DSTIMG); } } } //init image function initi_img () { &nbSp; if ($this->type== "jpg") { $this->im = imagecreatefromjpeg ($ THIS->SRCIMG); } if ($ this->type== "GIF") { $this->im = imagecreatefromgif ($this->srcimg); } if ($this->type== "png") { $this->im = Imagecreatefrompng ($this->srcimg); } } //processing Fillet function rounded_corner ($image, $size) { $topleft = true; $bottomleft = true; $bottomright = true; $topright = true; $corner _source = imagecreatefrompng (' rounded_corner.png '); $corner _width = imagesx ($corner _source); $ Corner_height = imagesy ($corner _source); $corner _resized = imagecreatetruecolor ($this->corner_radius, $ This->corner_radius); imagecopyresampled ($corner _resized, $corner _source, 0, 0, 0, 0, $ this->corner_radius, $this->corner_radius, $corner _width, $corner _height); $corner _width = Imagesx ($corner _resized); $corner _height = imagesy ($corner _resized); $white = Imagecolorallocate ($image, 255,255,255); $black = imagecolorallocate ($image, 0,0,0); //Top left Fillet if ($topleft == true) { $dest _x = 0; $dest _y = 0; imagecolortransparent ($corner _resized, $black); imagecopymerge ($image, $corner _resized, $dest _x, $dest _y, 0, 0, $corner _width, $corner _ HEIGHT,&NBSP;100); } / /lower left round corner if ($bottomleft == true) { $dest _x = 0; $dest _y = $size - $corner _height; $rOtated = imagerotate ($corner _resized, 90, 0); Imagecolortransparent ($rotated, $black); imagecopymerge ($ image, $rotated, $dest _x, $dest _y, 0, 0, $corner _width, $corner _height, &NBSP;100); } / /Lower right round corner if ($bottomright == true) { $dest _x = $size - $corner _width; $dest _y = $size - $corner _height; $rotated = imagerotate ($corner _resized, 180, 0); imagecolortransparent ($rotated, $black); Imagecopymerge ($image, $rotated, $dest _x, $dest _y, 0, 0, $corner _width, $ CORNER_HEIGHT,&NBSP;100); } //top Right round corner if ($topright == true) { $dest _x = $size - $corner _width; $dest _y = 0; $ Rotated = imagerotate ($corner _resized, 270, 0); &nbSp; imagecolortransparent ($rotated, $black); imagecopymerge ($image, $rotated, $dest _x, $dest _y, 0, 0, $corner _width, $corner _height, 100); } $image = imagerotate ($image, $this->angle, $white); return $image; } //Image Destination Address function dst_img () { $full _length = strlen ($this->srcimg); $type _length = strlen ($this->type); $name _length = $full _length-$type _length; $name = substr ($this->srcimg,0, $name _ length-1); $this->dstimg = $name. " _small.png "; }}//resizeimage (" Image Address ", " the width after processing ", " the height after processing ", " whether to crop ", " the degree of fillet ", "Tilt"), $img _file = ' sunset.jpg '; $corner = ' rounded_corner.png '; $resizeimage = new resizeimage ($img _file, $corner, ", ", "1", "6", "0"); >
PHP image Processing class: Support (thumbnail, crop, fillet, tilt)