How to use:
$img = new Iamge;
$img->resize (' dstimg.jpg ', ' srcimg.jpg ', 300, 400);
Description: This is proportional scaling, dstimg.jpg is the target file, Srcimg.jpg is the source file, the following is the target file width and height
$img->thumb (' dstimg.jpg ', ' scrimg.jpg ', 300, 300);
Description: This is in accordance with proportional thumbnails, such as commonly used in the avatar thumbnail, dstimg.jpg is the target file, Srcimg.jpg is the source file, the following is the target file width and height
This is for GD Coucay such trouble, if the use of Imagick words, only need two functions on the implementation of the above function, to check the document to find.
<?php
Class image{
public function Resize ($dstImg, $srcImg, $dstW, $dstH) {
& Nbsp;list ($srcW, $srcH) = getimagesize ($SRCIMG);
$scale = min ($dstW/$srcW, $dstH/$srcH);
$newW = Round ($srcW * $scale);
$newH = Round ($srcH * $scale);
$newImg = Imagecreatetruecolor ($newW, $newH);
$srcImg = Imagecreatefromjpeg ($SRCIMG);
imagecopyresampled ($newImg, $srcImg, 0, 0, 0, 0, $newW, $newH, $srcW, $srcH);
imagejpeg ($NEWIMG, $DSTIMG);
}
public function Thumb ($dstImg, $srcImg, $dstW, $dstH) {
list ($srcW, $srcH) = Getimag Esize ($SRCIMG);
$scale = max ($dstW/$srcW, $dstH/$srcH);
$newW = round ($dstW/$scale);
$newH = round ($dstH/$scale);
$x = ($srcW-$newW)/2;
$y = ($srcH-$NEWH)/2;
$newImg = Imagecreatetruecolor ($dstW, $dstH);
$srcImg = Imagecreatefromjpeg ($SRCIMG);
imagecopyresampled ($newImg, $srcImg, 0, 0, $x, $y, $dstW, $dstH, $newW, $newH);
imagejpeg ($NEWIMG, $DSTIMG);
}
}
Function Createfromtype ($type, $srcImg) {
$function = "Imagecreatefrom$type";
return $function ( $SRCIMG);
}
//To resolve problems with different picture formats