View Full Version : can you check image file properties using javascript.
MikoLone
07-17-2002, 03:22 PM
I have this script where you pass the a popup window the size that will fit the image so that it will be the same size as the picture. I was wondering if it is possible in javascript to check out the size of the picture so that I do not have to pass the size I want to the window. Is it possible?
:thumbsup: Thanks for the imput.
tamienne
07-17-2002, 05:26 PM
The image needs to be loaded before you can access it's properties. So, it's not really possible to do it unless you want to load the image twice...
MikoLone
07-17-2002, 05:40 PM
do you mean like preloading it? I am down to load them twice, I just need to know how. Do you have a script that might help me along?
x_goose_x
07-17-2002, 06:34 PM
<script>
function popupimag(file,bg,col) {
pophtml = "<body bgcolor='"+bg+"'><img src='"+file+"' style='position:absolute; left:0; top:0;'><div style='position:absolute; left:0; width:100%; color:"+col+"; text-align:center;' id='cls' onclick='self.close();'>[Close]</div></body>";
pop = window.open("","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,");
pop.document.write(pophtml)
w = pop.document.images[0].width+10;
h = pop.document.images[0].height+50;
pop.document.getElementById("cls").style.top = h - 50;
pop.resizeTo(w,h);
}
</script>
<a href="javascript: popupimag('imag.jpg','black','red');">pop</a>
Originally posted by MikoLone
I have this script where you pass the a popup window the size that will fit the image so that it will be the same size as the picture.
MikoLone, is there any way you can post that script because I am looking for something like that.
Thanks
Actually, I think x_goose_x's example does the samething.
MikoLone
07-17-2002, 09:32 PM
Thanks goose it works great.
I never thought about using %s for the width of the picture. Cool
:thumbsup:
Gecko makes this easy:
var newWin = window.open('bla.gif');
newWin.sizeToContent();
OR:
var image = new Image('bla.gif');
var newWin = window.open('bla.gif','','width=' + image.naturalWidth + ',height=' + image.naturalHeight);
:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.