Code for uploading images and creating thumbnails in the phpGD Library
-
- Image Upload -bbs.it-home.org
- File upload (only jpg images can be uploaded)
2. process the page upload_img.php
// Save the uploaded image
- $ Uploadfile = "upfiles/". $ _ FILES ['upfile'] ['name'];
- // Thumbnail storage 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 a file
$ DstW = 200; // Thumbnail width
- $ Dsomething = 200; // The height of the thumbnail.
$ Src_image = ImageCreateFromJPEG ($ uploadfile );
- $ SrcW = ImageSX ($ src_image); // Obtain the image width
- $ SrcH = ImageSY ($ src_image); // Obtain the image height
$ Dst_image = ImageCreateTrueColor ($ dstW, $ dsomething );
- ImageCopyResized ($ dst_image, $ src_image, 0, 0, 0, $ dstW, $ dsomething, $ srcW, $ srcH );
- ImageJpeg ($ dst_image, $ smallfile );
Echo 'file uploaded successfully ';
- Echo "";
- }
- ?>
The above code is relatively simple. if you are interested, you can study the gd library function in the php Manual. |