The classic PHP thumbnail generation program, based on the GD library, can specify the path to build and the width and height of the target usage method: In a PHP environment that supports the GD library, save the following code as a resize.php test
The classic PHP thumbnail generation program, based on the GD library, allows you to specify the build path and the width and height details of the build target.
How to use: In a PHP environment that supports the GD library, save the following code as a resize.php test
Copy the Code code as follows:
$FILENAME = "Image_name";
Create the width of the picture
$RESIZEWIDTH = 400;
Height of the resulting picture
$RESIZEHEIGHT = 400;
Create a path to a picture
$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 ("$FILENAME. jpg")) {
Unlink ("$FILENAME. jpg");
}
Resizeimage ($im, $RESIZEWIDTH, $RESIZEHEIGHT, $FILENAME);
Imagedestroy ($im);
}
}
?>
">
The above describes the customizable PHP thumbnail generation program requires the GD library support, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.