Jump to content

Image Size


Mememe

Recommended Posts

Well, I have an System, where the user can insert a link for there own avatar. The thing is, how do I make sure that if the image width and height is over 64 pixels, it goes to 64 pixels but if it was under 64 pixels or 64 pixels, it would stay at it's own size?Thanks, mememe. :)

Link to comment
Share on other sites

What you can do is this:Within the <head> tags:

<script type="text/javascript">function imageResize(id) {	if(document.getElementById(id).width > 64 || document.getElementById(id).height > 64) {		if(document.getElementById(id).width > document.getElementById(id).height) {		document.getElementById(id).style.width = "64px";		document.getElementById(id).style.height =  (document.getElementById(id).height/document.getElementById(id).width * 64) + "px";		}	}	return null;}</script>

For each image:

<img src="file1.jpg" alt="..." id="something" onload="imageResize('something')" /><img src="file2.jpg" alt="..." id="somethingelse" onload="imageResize('somethingelse')" />

Link to comment
Share on other sites

When they upload the image you should be able to open it and check it. If you are using PHP to handle the file upload you can use several functions to check the image size and resize it if necessary. It will be much more efficient to do that with PHP versus Javascript, with Javascript if they upload an image that's 500x500 you're still loading the full image on the page, just showing it smaller. With PHP you're resizing the actual file to take up less space and then you show it at full size on the page. That way they aren't downloading a 500x500 image only to see it at 64x64.http://www.php.net/manual/en/function.getimagesize.phphttp://www.php.net/manual/en/function.imag...atefromjpeg.phphttp://www.php.net/manual/en/function.imagecopyresampled.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...