This generates the thumbnail code, want it to be 600 width, and then the height proportionally how to get?

Source: Internet
Author: User
This generates the thumbnail code, want it to be 600 width, and then the height proportionally how to get it????
The code is on-line, the author notes that can be proportional!
But I set the height to 0, and it doesn't work. Can only be set fixed!
Now I want to make the width 600, the height is proportional. How do you get it???


/**
* Generate thumbnail functions (supported image formats: GIF, JPEG, PNG, and BMP)
* @author Ruxing.li
* @param string $src source picture path
* @param int $width thumbnail width (equal to zoom only when height is specified)
* @param int $width thumbnail height (equal to zoom only when width is specified)
* @param string $filename save path (direct output to browser if not specified)
* @return BOOL
*/
function Mkthumbnail ($src, $width = null, $height = NULL, $filename = null) {
if (!isset ($width) &&!isset ($height))
return false;
if (Isset ($width) && $width <= 0)
return false;
if (Isset ($height) && $height <= 0)
return false;

$size = getimagesize ($SRC);
if (! $size)
return false;

List ($src _w, $src _h, $src _type) = $size;
$SRC _mime = $size [' MIME '];
Switch ($src _type) {
Case 1:
$img _type = ' gif ';
Break
Case 2:
$img _type = ' jpeg ';
Break
Case 3:
$img _type = ' png ';
Break
Case 15:
$img _type = ' wbmp ';
Break
Default:
return false;
}

if (!isset ($width))
$width = $src _w * ($height/$src _h);
if (!isset ($height))
$height = $src _h * ($width/$src _w);

$imagecreatefunc = ' Imagecreatefrom '. $img _type;
$src _img = $imagecreatefunc ($SRC);
$dest _img = Imagecreatetruecolor ($width, $height);
Imagecopyresampled ($dest _img, $src _img, 0, 0, 0, 0, $width, $height, $src _w, $src _h);

$imagefunc = ' image '. $img _type;
if ($filename) {
$imagefunc ($dest _img, $filename);
} else {
Header (' Content-type: '. $src _mime);
$imagefunc ($dest _img);
}
Imagedestroy ($src _img);
Imagedestroy ($dest _img);
return true;
}

Here to set the picture to 600x proportional how to get?

$result = Mkthumbnail (' 1.JPG ', ' 2.jpg ');
?>

------to solve the idea----------------------
$result = Mkthumbnail (' 1.JPG ', +, NULL, ' 2.jpg ');

Didn't he say it clearly?
* @param int $width thumbnail width (equal to zoom only when height is specified)
* @param int $width thumbnail height (equal to zoom only when width is specified)
  • 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.