This article provides a php image processing class for free: scaling down, cropping, rounded corners, and skewed code. He can cut out pictures of different styles. Haha, it is much better than other online cut pictures.
Php tutorial image processing class: scaling, cropping, rounded corner, and skew
Class resizeimage
{
// Image type
Var $ type;
// Actual width
Var $ width;
// Actual height
Var $ height;
// Change the width
Var $ resize_width;
// The height after the change
Var $ resize_height;
// Whether to cut the image
Var $ cut;
// Source Image
Var $ srcimg;
// Target image address
Var $ dstimg;
// Rounded corner Source
Var $ corner;
Var $ im;
Function resizeimage ($ img, $ corner, $ wid, $ hei, $ c, $ corner_radius, $ angle)
{
$ This-> srcimg = $ img;
$ This-> corner = $ corner;
$ This-> resize_width = $ wid;
$ This-> resize_height = $ hei;
$ This-> cut = $ c;
$ This-> corner_radius = $ corner_radius;
$ This-> angle = $ angle;
// Image type
$ This-> type = substr (strrchr ($ this-> srcimg, "."), 1 );
// Initialize the image
$ This-> initi_img ();
// Target image address
$ This-> dst_img ();
//--
$ This-> width = imagesx ($ this-> im );
$ This-> height = imagesy ($ this-> im );
// Generate an image
$ This-> newimg ();
Imagedestroy ($ this-> im );
}
Function newimg ()
{
// Ratio of the changed image
$ Resize_ratio = ($ this-> resize_width)/($ this-> resize_height );
// Ratio of the actual image
$ Ratio = ($ this-> width)/($ this-> height );
If ($ this-> cut) = "1 ")
// Cut the image
{
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)
// The width is preferred.
{
$ 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 );
}
}
Else
1 2 3