First to a simple PHP upload image to generate thumbnails of the detailed code, to share with you for your reference, the specific content as follows
<?php function Createthumbnail ($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality) {$details =
GetImageSize ("$imageDirectory/$imageName") or Die (' please upload images. ');
$type = Preg_replace (' @^.+ (? <=/) (. +) $@ ', ' $ ', $details [' mime ']); Eval (' $srcImg = Imagecreatefrom '. $type.
("$imageDirectory/$imageName");
$thumbHeight = $details [1] * ($thumbWidth/$details [0]);
$THUMBIMG = Imagecreatetruecolor ($thumbWidth, $thumbHeight);
Imagecopyresampled ($THUMBIMG, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $details [0], $details [1]); Eval (' image '. $type. '
($THUMBIMG, "$thumbDirectory/$imageName".
(($type = = ' jpeg ')? ', $quality ': '); ');
Imagedestroy ($SRCIMG);
Imagedestroy ($THUMBIMG); foreach ($_files["Pictures"] ["error"] as $key => $error) {if ($error = = UPLOAD_ERR_OK) {$tmp _name = $_files["Pictur
Es "] [" tmp_name "] [$key];
$name = $_files["Pictures" ["Name"] [$key];
Move_uploaded_file ($tmp _name, "data/$name"); Createthumbnail ("/location/of/main/image", $name, "/location/to/store/thumb", 120, 80);
Thumb width:: Thumb = Quality (1-100)}?>
Next, we recommend an example PHP use the GD library to upload pictures and create thumbnails, directly look at the code:
The GD library is a very powerful library of PHP for image manipulation.
First add one line to the php.ini:extension=php_gd2.dll
Restart Apache, do a test page var_dump (Gd_info ()); The output data indicates that the GD library reference was successful.
Picture upload page upload.html
Process Page upload_img.php
<?php
//Upload image save address
$uploadfile = "upfiles/". $_files[' upfile ' [' name '];
Thumbnail save address
$smallfile = "Upfiles/small_". $_files[' upfile ' [' name '];
if ($_files[' upfile '] [' type ']!= ' image/jpeg ')
{
echo ' file type error ';
}
else
{
move_uploaded_file ($_files[' upfile '] [' tmp_name '], $uploadfile);//upload file
$dstW =200;//thumbnail width
$dstH =200;//thumbnail high
$src _image=imagecreatefromjpeg ($uploadfile);
$srcW =imagesx ($src _image); Get picture width
$srcH =imagesy ($src _image);//Get Picture high
$dst _image=imagecreatetruecolor ($dstW, $dstH);
Imagecopyresized ($dst _image, $src _image,0,0,0,0, $dstW, $dstH, $srcW, $srcH);
Imagejpeg ($dst _image, $smallfile);
echo ' File upload success <br> ';
echo "
We hope to learn PHP program design help, thank you for your support.