Thumbnail image
The classic PHP thumbnail generation program, based on the GD library, can specify the build path and build target of the wide-high details
Usage: In a PHP environment that supports the GD library, save the following code as a resize.php test
?
$FILENAME="Image_name";
//Generate the width of the picture
$RESIZEWIDTH= -;
//Build the height of the picture
$RESIZEHEIGHT= -;
//Build the path of the picture
$uploaddir="C:/winnt/temp";
functionResizeimage($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("$FILENAME. jpg")){
unlink("$FILENAME. jpg");
}
Resizeimage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);
Imagedestroy($im);
}
}
?>
?Echo ($FILENAME.". jpg?reload=".Rand(0,999999)); ?>"><br><br>
<form enctype= "Multipart/form-data" method= "POST" >
<br>
<input type= "file" name= "image" Size= "a" value= "browse" ><p>
<input type= "Submit" value= "Upload picture" >
</form>
</body>