get image size and how to make changes

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: get image size and how to make changes

 
0
  #11
Dec 2nd, 2008
I came up to this as for the final solution... Have fun!
This is a valid xHTML 1.0 Strict


  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
  4. <head profile="http://www.w3.org/2005/10/profile">
  5. <title>Get The Image Size</title>
  6. <script type="text/javascript">
  7. /* <![CDATA[ */
  8. var img = document.getElementsByTagName('img');
  9. var links = document.getElementsByTagName('a');
  10. var imageWidth = [];
  11. var imageHeight = [];
  12. function myImage()
  13. {
  14. for ( var x = 0; img.length; x++ ) {
  15. img[x].id = 'image' + x;
  16. links[x].id = 'show' + img[x].id;
  17. imageWidth[imageWidth.length] = img[x].width;
  18. imageHeight[imageHeight.length] = img[x].height;
  19. links[x].style.visibility = 'hidden';
  20. if ( img[x].width > 300 ) { img[x].width = 300; }
  21. img[x].onmouseover = function(e) {
  22. e = e ? e : window.event;
  23. t = e.target ? e.target : e.srcElement;
  24. if (document.images && img && t.width < 300) { links['show'+t.id].style.visibility = 'visible'; links['show'+t.id].href = t.src; }
  25. }
  26. links[x].onclick = function() {
  27. for (var i = 0; i < this.id.length; i++) {
  28. var uri = this.href;
  29. var ids = this.id;
  30. var ref = ids.charAt(i); } this.href = 'javascript:void(0);';
  31. window.open(uri,target="_blank",'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,width=' + imageWidth[ref] + ',height=' + imageHeight[ref] + '\'');
  32.  
  33. }
  34. }
  35. }
  36. if (window.addEventListener)
  37. window.addEventListener('load',myImage,false);
  38. else if (window.attachEvent)
  39. window.attachEvent('onload',myImage);
  40. else if (document.getElementById)
  41. window.onload = myImage;
  42. /* ]]> */
  43. </script>
  44. </head>
  45. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  46. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  47. <body>
  48. <p><img src="image1" alt="image1" /><br />
  49. <a href="*">Image1</a></p>
  50. <p><img src="image2" alt="image2" /><br />
  51. <a href="*">Image2</a></p>
  52. <p><img src="image3" alt="image3" /><br />
  53. <a href="*">Image3</a></p>
  54. </body>
  55. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: get image size and how to make changes

 
0
  #12
Dec 2nd, 2008
Oops! I forgot to change it! Try to see line#24
if (document.images && img && t.width < 300) it all means that if your images is less than or lower than 300pixed wide then the corresponding link for that specific image will show up. But what is if the images is greater the 300px then the that images should be converted at exact width of 300px and then show specific link for that image.
For that outcome simply change the above code to this
if (document.images && img && t.width > 300) dont forget to mark the thread solved. Good day to you...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: get image size and how to make changes

 
0
  #13
Dec 2nd, 2008
Oops! I forgot to change it! Try to see line#24
if (document.images && img && t.width < 300) it all means that if your images is less than or lower than 300pixed wide then the corresponding link for that specific image will show up. But what you want is if the images is greater the 300px then that images should be converted at exact width of 300px and then show specific link for those images.
For that outcome simply change the above code to this
if (document.images && img && t.width > 300) dont forget to mark the thread solved. Good day to you...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 22
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: get image size and how to make changes

 
0
  #14
Dec 4th, 2008
Hi Essential,

Thanks for This.

But still my problem is not solved......

I used above code

The changes done by me in above are:
1] Instead of
<img src="image1" OR src="image2" OR src="image3" alt="image1" />
i use actual filename as below
<img src="limits.gif" alt="image1" id="image1" /> and so on
I am using IE 6 SP 2 and FF 3.0
****************************
Now I am facing below problems:
1] Images having more than 300px width are showing as it is on HTML page. [instead of showing 300px in width on html page]
2] Links are generating to all images though they are less [i.e. below 300px width]
3] when click on <a> only goes to next page and not showing the image. [Not opening in another popup with image]

Please suggest where i am wrong and how can I overcome the same.

****************************

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head profile="http://www.w3.org/2005/10/profile">
<title>Get The Image Size</title>
<script type="text/javascript">
<!--
var img = document.getElementsByTagName('img');
var links = document.getElementsByTagName('a');
var imageWidth = [];
var imageHeight = [];
function myImage()
{
for ( var x = 0; img.length; x++ ) {
img[len].id = 'image' + x;
links[len].id = 'show' + img[x].id;
imageWidth[imageWidth.length] = img[x].width;
imageHeight[imageHeight.length] = img[x].height;
links[x].style.visibility = 'hidden';
if ( img[x].width > 300 ) { img[x].width = 300px; }
img[x].onmouseover = function(e) {
e = e ? e : window.event;
t = e.target ? e.target : e.srcElement;
if (document.images && img && t.width > 300) { links['show'+t.id].style.visibility = 'visible'; links['show'+t.id].href = t.src; }
}
links[x].onclick = function() {
for (var i = 0; i < this.id.length; i++) {
var uri = this.href;
var ids = this.id;
var ref = ids.charAt(i); } this.href = 'javascript:void(0);';
window.open(uri,target="_blank",'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,width=' + imageWidth[ref] + ',height=' + imageHeight[ref] + '\'');
if (window.addEventListener)
window.addEventListener('load',myImage,false);
else if (window.attachEvent)
window.attachEvent('onload',myImage);
else if (document.getElementById)
window.onload = myImage;
}
}
}

-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
</head>
<body>
<p><img src="limits.gif" alt="image1" id="image1" /><br />
<a href="*">Image1</a></p>
<p><img src="after_controls_2.gif" alt="image2"  id="image2"/><br />
<a href="*">Image2</a></p>
<p><img src="pic23281.jpg" alt="image3"  id="image3"/><br />
<a href="*">Image3</a></p>
</body>
</html>

****************************
Please help.
****************************

cheers,
Mahesh
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: get image size and how to make changes

 
0
  #15
Dec 4th, 2008
All of my codes is tested before released!
It's working nice with me, since am using Opera 9.6 -

Things gone bad in your code! From this line -->
  1. /* if (img[x].width > 300) { img[x].width = 300px; -- to fix simply copy the code below... */
  2.  
  3. if ( img[x].width > 300 ) { img[x].style.width = '300px'; }
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 22
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: get image size and how to make changes

 
0
  #16
Dec 8th, 2008
Hi Essential,

Is there any way that can help me.

Please suggest.


Thanks,
Mahesh
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 4751 | Replies: 15
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC