This example describes how PHP uses the GD library to create thumbnail images of pictures. Share to everyone for your reference. The specific analysis is as follows:
Static HTML code for uploading pages:
The corresponding upload.php file code:
<?php
$uploadfile = "upfiles/". $_files[' upfile ' [' name '];
The file name and path
$smallfile = "Upfiles/small_" after the upload. $_files[' upfile ' [' name '];
File name and path
if ($_files[' upfile '] [' type ']!= "Image/pjpeg")
{
echo "file type error";//Output error message
}
Else
{
move_uploaded_file ($_files[' upfile '] [' tmp_name '], $uploadfile);
Upload file
$dstW = 200;//Set the width of the thumbnail
$dstH = 200;//Set the height of the thumbnail
$src _image = Imagecreatefromjpeg ($uploadfile); c16/>//reads the JPEG file and creates the image object
$srcW = Imagesx ($src _image);//Get the image wide
$srcH = Imagesy ($src _image);//Get high
$ for image Dst_image = Imagecreatetruecolor ($dstW, $dstH);
Create a new Image Object
imagecopyresized ($dst _image, $src _image,0,0,0,0, $dstW, $dstH, $srcW, $srcH);
Writes the image to the new Image object
imagejpeg ($dst _image, $smallfile) after the size is redefined;//create thumbnail file
echo "File upload complete <BR>"//Output Upload success Information
echo "</img>";
Show thumbnails on the page
}
?>
I hope this article will help you with your PHP program design.