Customizable PHP thumbnail Generation Program (supported by the GD library) typical PHP thumbnail Generation Program. Based on the GD library, you can specify the width and height of the generated path and the target. Usage: in the PHP environment that supports the GD library, save the following code as resize. php Testing
A typical PHP thumbnail generator. Based on the GD library, you can specify the path to be generated and the width and height of the target.
Usage: in the PHP environment that supports the GD library, save the following code as resize. php for testing.
The Code is as follows:
$ FILENAME = "image_name ";
// Generate the Image Width
$ RESIZEWIDTH = 400;
// Generate the Image Height
$ RESIZEHEIGHT = 400;
// Generate the image path
$ Uploaddir = "c:/winnt/temp ";
Function ResizeImage ($ im, $ maxwidth, $ maxheight, $ name ){
Global $ uploaddir;
$ 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, $ uploaddir. $ name. ". jpg ");
ImageDestroy ($ newim );
} Else {
ImageJpeg ($ im, $ uploaddir. $ 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 );
ImageDestroy ($ im );
}
}
?>
">