Jump to content

Image size


drisate

Recommended Posts

Hey guys i need to check the image size of an image and if it's smaller then 300px large then load the original image ... But i have no idea how to do that in javascript lol this is how i would do it in PHP

 

list($width, $height, $type, $attr) = getimagesize('media/original/'.$list[image1]);
if ($width<'300'){
[...]

 

This is my Javascript code

		  if (image_1!== '') {
	          html +='<img src="media/medbig/' + image_1 + '" width="300" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'
	      } else if (image_2!== '') {
	          html +='<img src="media/medbig/' + image_2 + '" width="300" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'
	      } else if (image_3!== '') {
	          html +='<img src="media/medbig/' + image_3 + '" width="300" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'
	      } else if (image_4!== '') {
	          html +='<img src="media/medbig/' + image_4 + '" width="300" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'
	      } else if (image_5!== '') {
	          html +='<img src="media/medbig/' + image_5 + '" width="300" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'
	  }

 

if media/original/' + image_5 + ' is smaller then 300px large use him in stead of media/medbig/' + image_5 + '

Link to comment
Share on other sites

This is what i tryed so fare but it's not working

 

		      imgFile.src = 'media/original/' + image_1;
               
               if (imgFile.width < 300) {
                 html +='<img src="media/original/' + image_1 + '" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'                
               }else{
                 html +='<img src="media/medbig/' + image_1 + '" width="300" style="border: 1px solid black;" id="img_preview_' + id + '"><br><br>'
               }

Link to comment
Share on other sites

<html>
<head>
<script type="text/javascript">
function imgSize(img)
{
   alert(img.offsetHeight + "," + img.offsetWidth);
}
</script>
</head>
<body>
<img src="http://www.google.com/logos/logo.gif" onclick="imgSize(this)"/>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.