Php can generate thumbnails more easily. if you have any questions, you may want to implement the function of uploading images and generating thumbnails. you have found the code disconnected from the Internet and succeeded. If you want to generate two images at a time-one large thumbnail and one small thumbnail, the following code is provided: Notice: Undefinedvariable: RESIZEWIDTHinD: WWWqiangyuanup. phponline17Notice: Unde php generates more thumbnails. if you have any questions, please refer
If you want to implement the function of uploading images and generating thumbnails, you can find the code disconnected from the Internet.
If you want to generate two images at a time-one large thumbnail and one small thumbnail, the following code is provided:
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 code is as follows:
//************************************** **
// Generate a thumbnail =============================================== ====
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 image file name
$ RESIZEWIDTH = 150; // The width of the generated image
$ RESIZEHEIGHT = 113; // The height of the generated image
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 ("your filename.jpg ")){
Unlink ("your filename.jpg ");
}
ResizeImage ($ im, $ RESIZEWIDTH, $ RESIZEHEIGHT, $ FILENAME); // generates a thumbnail.
ResizeImage ($ im, 600,450, "product/max/". date ("YmdHis"); // generate a large image
ImageDestroy ($ im );
}
}
//************************************** **
?>
------ Solution --------------------
Assign initial values to $ RESIZEWIDTH and $ RESIZEHEIGHT at the function entry.
Function ResizeImage ($ im, $ maxwidth, $ maxheight, $ name ){
$ RESIZEWIDTH = $ RESIZEHEIGHT = false;
....