Constraining pictures uploaded sizes...
Moderator: General Moderators
Constraining pictures uploaded sizes...
Hello,
I need a slight help with something I have planned to complete my web site project.
Currently I am allowing users to upload PNG, GIF and JPG to my site.
However, I have noticed when uploading wide(anything over 650px) and high(anything over 800px) pics that it makes the web page look pretty messy.
Is there anything I can do to constrain the pictures width and height. In a perfect world, have code in the picture display file to reduce them to fit on the page, then have a link to view it in a new window?
Any help would be greatly appreciated.
Mike.
I need a slight help with something I have planned to complete my web site project.
Currently I am allowing users to upload PNG, GIF and JPG to my site.
However, I have noticed when uploading wide(anything over 650px) and high(anything over 800px) pics that it makes the web page look pretty messy.
Is there anything I can do to constrain the pictures width and height. In a perfect world, have code in the picture display file to reduce them to fit on the page, then have a link to view it in a new window?
Any help would be greatly appreciated.
Mike.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
getimagesize()
There are many many threads about creating thumbnails here. There are many threads containing thumbnailing code here. Look in Code Snippets, which has several of these.
Alternately, you could just tell the image to adjust its size displayed but not actually resize it (however it may look "bad") using the width and height attributes found in <img> tags.
There are many many threads about creating thumbnails here. There are many threads containing thumbnailing code here. Look in Code Snippets, which has several of these.
Alternately, you could just tell the image to adjust its size displayed but not actually resize it (however it may look "bad") using the width and height attributes found in <img> tags.
Still a thumbnail. Just a really big one.invision wrote:It's not so much a thumbnail I want to make, but just to rescale it for display so its underneath a specific horizontal and width that makes it look presentable on screen.
My preferred maximum width is 650px and preferred maximum height is 800px.
Here's how I did it :
Output File, I echoed :
Upload File :
I just added a 'width' and 'height' to the table of the database.
Output File, I echoed :
Code: Select all
<a href="show_picture.php?id='. $_GET['id'] .'" target="_blank"><img src="show_picture.php?id='. $_GET['id'] .'" alt="' . $row['image_name'] . '" width="' . $row['width'] . '" height="' . $row['height'] . '" border="1"></a>Code: Select all
$pic = getimagesize($filename);
$width = $pic[0];
$height = $pic[1];
if ($width > 600 || $height > 800) {
$widthdiff = 600/$width;
$heightdiff = 800/$height;
$biggest = min($widthdiff,$heightdiff);
$newwidth = $biggest*$width;
$newheight = $biggest*$height;
}- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Indeed. That is very bad practice. Imagine if a user uploaded a 5mb image with 2000 width and 3000 height.
Every user wanting to view the image would have to download ~5mb whereas if done properly they would see a better quality image and have to download about a fifth of the data.
Read some of the previous comments and rethink your code.
Every user wanting to view the image would have to download ~5mb whereas if done properly they would see a better quality image and have to download about a fifth of the data.
Read some of the previous comments and rethink your code.