Equal scale generated thumbnail PHP program This program is very implementation, but just used to come in and so on to generate thumbnails oh, you have to upload files to the server, and then the function to operate, a friend need reference.
PHP Tutorial Program for equal scale generation of thumbnails
This program is very implementation, but only used to come in, such as proportional generation of thumbnails oh, you have to upload files to the server, and then this function to operate, the need for a friend reference.
function resizeimg ($IMGSRC, $resize _width, $resize _height, $isCut =false) {
Type of picture
$type = substr (STRRCHR ($IMGSRC, "."), 1);
Initializing an image
if ($type = = "jpg") {
$im = Imagecreatefromjpeg ($IMGSRC);
}
if ($type = = "gif") {
$im = Imagecreatefromgif ($IMGSRC);
}
if ($type = = "png") {
$im = Imagecreatefrompng ($IMGSRC);
}
Destination image Address
$full _length = strlen ($IMGSRC);
$type _length = strlen ($type);
$name _length = $full _length-$type _length;
$name = substr ($IMGSRC, 0, $name _length-1);
$dstimg = $name. "_s." $type;
$width = Imagesx ($im);
$height = Imagesy ($im);
Creating images
The proportions of the altered image
$resize _ratio = ($resize _width)/($resize _height);
Ratio of actual images
$ratio = ($width)/($height);
if (($isCut) = = 1)//crop
{
if ($ratio >= $resize _ratio)//High priority
{
$newimg = Imagecreatetruecolor ($resize _width, $resize _height);
Imagecopyresampled ($newimg, $im, 0, 0, 0, 0, $resize _width, $resize _height, (($height) * $resize _ratio), $height);
Imagejpeg ($newimg, $dstimg);
}
if ($ratio < $resize _ratio)//Width First
{
$newimg = Imagecreatetruecolor ($resize _width, $resize _height);
Imagecopyresampled ($newimg, $im, 0, 0, 0, 0, $resize _width, $resize _height, $width, (($width)/$resize _ratio));
Imagejpeg ($newimg, $dstimg);
}
} else//No drawing
{
if ($ratio >= $resize _ratio) {
$newimg = Imagecreatetruecolor ($resize _width, ($resize _width)/$ratio);
Imagecopyresampled ($newimg, $im, 0, 0, 0, 0, $resize _width, ($resize _width)/$ratio, $width, $height);
Imagejpeg ($newimg, $dstimg);
}
if ($ratio < $resize _ratio) {
$newimg = Imagecreatetruecolor (($resize _height) * $ratio, $resize _height);
Imagecopyresampled ($newimg, $im, 0, 0, 0, 0, ($resize _height) * $ratio, $resize _height, $width, $height);
Imagejpeg ($newimg, $dstimg);
}
}
Imagedestroy ($im);
}
Call method is simple, direct resizeimg can be, reference is very simple.
http://www.bkjia.com/PHPjc/632978.html www.bkjia.com true http://www.bkjia.com/PHPjc/632978.html techarticle equal scale generated thumbnail PHP program This program is implemented, but only used to come in and so on to generate thumbnails oh, you have to upload files to the server, and then the function to operate, there is ...