Very simple PHP thumbnail generation program source code .? $ FILENAMEimage_name; width of the generated image $ RESIZEWIDTH400; height of the generated image $ RESIZEHEIGHT400; functionResizeImage ($ im, $ maxwidth, $ maxheight, $ name) {$ widthimages
$ FILENAME = "image_name ";
// Generate the image width
$ RESIZEWIDTH = 400;
// Generate the image height
$ RESIZEHEIGHT = 400;
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 ")){
Www.phperz.com
$ 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 ");
}
}
If ($ _ 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); www ~ Phperz ~ Com
ImageDestroy ($ im );
}
}
?>
">
Http://www.bkjia.com/PHPjc/508420.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508420.htmlTechArticle? $ FILENAME = image_name; // width of the generated image $ RESIZEWIDTH = 400; // height of the generated image $ RESIZEHEIGHT = 400; function ResizeImage ($ im, $ maxwidth, $ maxheight, $ name) {$ width = images...