_php Tutorial for PHP programs that generate thumbnails in equal proportions

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.