Jump to content

Getting Image Source


adam291086

Recommended Posts

Correct me if i am wrong but you want the actual size of the image am i right?

 

There is 2 ways to solve that problem.

 

1. get the image width server side.

 

2. Get the image width when the page has fully loaded. I found a quick way to solve that using mootools

 

/* Load Event fires when the whole page is loaded, included all images */
window.addEvent('load', function() {
  //in here you can execute your function to get your image width since the page has fully loaded
});

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/101614-getting-image-source/#findComment-521191
Share on other sites

@ DJ Kat

 

I am new to javascript. That function will load when the window loads. How can i call on a varable out of that function.

 

/* Load Event fires when the whole page is loaded, included all images */
window.addEvent('load', function() {
var adam = document.getElementById("myimage").height
});

 

 

how can i call upon adam later on

Link to comment
https://forums.phpfreaks.com/topic/101614-getting-image-source/#findComment-521217
Share on other sites

I'm sure this will help you out this is a fully working example

 

<script src="mootools-release-1.11.js"></script>
<script>

window.addEvent('load', function() {
  
  //the $("myimage") equals the document.getElementById("myimage") method mootools style
  var imageElement=$("myimage");
  
  //create an image object
  var image= new Image();
  
  //set the source of the image object
  image.src = $("myimage").src ;
  
  //alert the image height
  alert(image.height);

});
</script>
<img id="myimage" src="2426402588_f7486e0eb2.jpg" />

Link to comment
https://forums.phpfreaks.com/topic/101614-getting-image-source/#findComment-521531
Share on other sites

Archived

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

×
×
  • 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.