By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,711 Members | 2,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,711 IT Pros & Developers. It's quick & easy.

PHP image Uploading along with thumbnail

P: 13
hi,

i've this situations where user will upload images..my code works fine for uploading images.. but i need to create auto thumbnail picture (of the same image) whenever user upload images... help me how to create thumbnail picture..
is my question clear?

thk in advance
Apr 14 '07 #1
Share this Question
Share on Google+
5 Replies


Motoma
Expert 2.5K+
P: 3,235
You can use the height and width attributes of the <img> tag to adjust the size of the image.

hi,

i've this situations where user will upload images..my code works fine for uploading images.. but i need to create auto thumbnail picture (of the same image) whenever user upload images... help me how to create thumbnail picture..
is my question clear?

thk in advance
Apr 14 '07 #2

P: 13
@ Motoma

here the page shows the all the images which user has uploaded, if i use the height and width to reduce the image display size, eventually the page will take much time to load...

hope i'm clear...

thkx for replying
Apr 15 '07 #3

cyberking
P: 84
Hi Deejam

In that case, you can as well write your own image resizing function. Not a big deal. Get the size of the image using the getimagesize function. Store the return values in a variable. Perform reduction on the width and the height returned by the getimagesize function and then return the new reduced width and heigth to the width and height parameters in the img tag.

More if you need help
Regards
CyberKing
Apr 15 '07 #4

Motoma
Expert 2.5K+
P: 3,235
Cyberking's method is valid; if you want to do more research on this method, you should look up the PHP GD functions.
Apr 16 '07 #5

P: 13
Thanks cyberking and Motoma...

here is the code for creating thumbnail to the uploading picture...

echo "Creating thumbnail for $filename <br />";
// Load image and get image size
$orgimg = imagecreatefromjpeg($filename);
$width = imagesx($orgimg);
$height = imagesy($orgimg);
// Setting new width and height for thumbnail size
$newwidth = 100; //any size as you wish
$newheight = floor($height*($newwidth/$width));
// Creating new temporary image
$tmpimg = imagecreatetruecolor($newwidth, $newheight);
// Copy and resize old image into new image
imagecopyresized($tmpimg, $orgimg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
// Save thumbnail into a file
imagejpeg($tmpimg, $path_to_thumbs_dir.$filename);


i welcome any suggestion/correction...
Apr 16 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.