PHP generates thumbnails more capable of encountering point-related issues

Source: Internet
Author: User
Tags imagejpeg
PHP generated thumbnails more capable, encountered some problems, ask you
Want to implement a upload image and generate thumbnails of the function, from the Internet to find the code, also succeeded.
To generate two photos at a time-a large thumbnail, a small thumbnail, the result is the following code:

notice:undefined variable:resizewidth in D:\WWW\qiangyuan\up.php on line 17
notice:undefined variable:resizewidth in D:\WWW\qiangyuan\up.php on line 23



The source program code is as follows:

//****************************************
Generate Thumbnails ========================================

function Resizeimage ($im, $maxwidth, $maxheight, $name) {
$width = Imagesx ($im);
$height = Imagesy ($im);
if ($maxwidth && $width > $maxwidth) | | ($maxheight && $height > $maxheight)) {
if ($maxwidth && $width > $maxwidth) {
$widthratio = $maxwidth/$width;
$RESIZEWIDTH =true;
}
if ($maxheight && $height > $maxheight) {
$heightratio = $maxheight/$height;
$RESIZEHEIGHT =true;
}
if ($RESIZEWIDTH && $RESIZEHEIGHT) {
if ($widthratio < $heightratio) {
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif ($RESIZEWIDTH) {
$ratio = $widthratio;
}elseif ($RESIZEHEIGHT) {
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if (function_exists ("imagecopyresampled")) {
$newim = Imagecreatetruecolor ($newwidth, $newheight);
Imagecopyresampled ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = Imagecreate ($newwidth, $newheight);
Imagecopyresized ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
Imagejpeg ($newim, $name. ". jpg");
Imagedestroy ($newim);
}else{
Imagejpeg ($im, $name. ". jpg");
}
}

$FILENAME = "product/min/". Date ("Ymdhis"); Small picture file name
$RESIZEWIDTH = 150; Create the width of the picture
$RESIZEHEIGHT = 113; Height of the resulting picture



if (isset ($_files[' image ' [' size '])) {
if ($_files[' image ' [' type '] = = "Image/pjpeg") {
$im = imagecreatefromjpeg ($_files[' image ' [' tmp_name ']);
}elseif ($_files[' image ' [' type '] = = "Image/x-png") {
$im = imagecreatefrompng ($_files[' image ' [' tmp_name ']);
}elseif ($_files[' image ' [' type '] = = "Image/gif") {
$im = imagecreatefromgif ($_files[' image ' [' tmp_name ']);
}


if ($im) {
if (File_exists ("$FILENAME. jpg")) {
Unlink ("$FILENAME. jpg");
}

Resizeimage ($im, $RESIZEWIDTH, $RESIZEHEIGHT, $FILENAME); Generate a small image
Resizeimage ($im, 600,450, "product/max/". Date ("Ymdhis")); Generate a larger image
Imagedestroy ($im);
}
}

//****************************************
?>












------Solution--------------------
Assigning initial values to $resizewidth and $RESIZEHEIGHT at the entrance of a function

function Resizeimage ($im, $maxwidth, $maxheight, $name) {
$RESIZEWIDTH = $RESIZEHEIGHT = false;
....
  • 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.