Page 1 of 1

Constraining pictures uploaded sizes...

Posted: Sun Feb 19, 2006 7:22 am
by invision
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.

Posted: Sun Feb 19, 2006 9:20 am
by feyd
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.

Posted: Mon Feb 20, 2006 2:32 am
by invision
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.

Posted: Mon Feb 20, 2006 2:34 am
by feyd
most of the thumbnailing scripts can be told what size to scale down to, if scaling is needed. Thumbnailing is being used in a generic sense here where it refers to the script resizing an image; that's all.

Posted: Mon Feb 20, 2006 3:03 am
by onion2k
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.
Still a thumbnail. Just a really big one.

Posted: Mon Feb 20, 2006 9:19 am
by invision
Here's how I did it :

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>
Upload File :

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;
	}
I just added a 'width' and 'height' to the table of the database.

Posted: Mon Feb 20, 2006 10:29 am
by onion2k
So you're making the user's browser rescale the image? I hope image quality isn't important to you. Nor bandwidth for that matter.

Posted: Mon Feb 20, 2006 10:32 am
by JayBird
invision: that is a great example of how not to achive what you want

edit: as onion2k says...image quality and bandwidth would be a concern

Posted: Mon Feb 20, 2006 10:52 am
by jayshields
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. :)