473,503 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with image display please...

DDL
I am trying to create a simple web gallery to swap my images at
http://dev.lenosphotography.com

Go to the family section (should open a image bar at bottom - you may have
to scroll down - I have not finalized placement) - when you click on the
image thumbnail it calls a page (passing the reference to the "image name"
with this code. The swapfade code basicall swaps via fading one image for
another.. so I load the blank jpg with the size set to the real images W/H -
then call the swapfade function...

<script language="javascript1.2" type="text/javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src = '<%=Request.QueryString( "photo" )%>';

iHeight=img1.height;
iWidth=img1.width;

document.write ("<img src='images/photoblank.jpg' border='1' id='photo'
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'<%=Requ est.QueryString(
"photo" )%>', '1', '');

</script>

_________________________________________________-

This works 99% of the time - but every so often the image comes up with
width and height = 0 - I am sure that it is due to the image not being fully
loaded before the img1.height line is called.. I have scoured the net on
this and found where I need to make sure the image is complete/loaded before
testing for it's height and width- nothing I have tried has worked yet...

Thanks for your help!
Feb 20 '06 #1
11 1611
Hiya Doug

Have you tried the onload event handler?

You will need to move everything after img1.src = <%..... into a
separate function then set img1.onload to the name of this function.

Something like this

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

<script language="javascript1.2" type="text/javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src = '<%=Request.QueryString( "photo" )%>';
img1.onload = imgLoaded;

function imgLoaded( anImg ) { //anImg is set automatically....
iHeight=anImg.height;
iWidth=anImg.width;

document.write ("<img src='images/photoblank.jpg' border='1'
id='photo'
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'<%=Requ est.QueryString(
"photo" )%>', '1', '');
}
</script>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Is that any good to you?
tihu

Feb 20 '06 #2
DDL
I'll give it a try and report back...THANKS!
"tihu" <ti********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hiya Doug

Have you tried the onload event handler?

You will need to move everything after img1.src = <%..... into a
separate function then set img1.onload to the name of this function.

Something like this

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

<script language="javascript1.2" type="text/javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src = '<%=Request.QueryString( "photo" )%>';
img1.onload = imgLoaded;

function imgLoaded( anImg ) { //anImg is set automatically....
iHeight=anImg.height;
iWidth=anImg.width;

document.write ("<img src='images/photoblank.jpg' border='1'
id='photo'
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'<%=Requ est.QueryString(
"photo" )%>', '1', '');
}
</script>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Is that any good to you?
tihu

Feb 20 '06 #3
Hiya.

Sorry I made a mistake in my above reply.

The imgLoaded function doesnt get a copy of the image, it receives an
event object.

So the imgLoaded function needs to be

function imgLoaded( event ) {
iHeight=img1.height;
iWidth=img1.width;

Good luck

Feb 20 '06 #4
DDL
hmm... look over... see anythign amiss? hit the site... not working exactly
right.. not getting the image?

<script language="javascript1.2" type="text/javascript">

img1 = new Image();
img1.src = '<%=Request.QueryString( "photo" )%>';
img1.onload = imgLoaded;

function imgLoaded( event ) {
var iWidth = 0;
var iHeight = 0;
iHeight = img1.height;
iWidth = img1.width;

document.write ("<img src='images/photoblank.jpg' border='1' id='photo'
width=", iWidth, " height=", iHeight, ">");
alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'<%=Requ est.QueryString(
"photo" )%>', '1', '');
}

</script>

"tihu" <ti********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hiya.

Sorry I made a mistake in my above reply.

The imgLoaded function doesnt get a copy of the image, it receives an
event object.

So the imgLoaded function needs to be

function imgLoaded( event ) {
iHeight=img1.height;
iWidth=img1.width;

Good luck

Feb 20 '06 #5
No I don't know.

Would you add alert( "src=" + img1.src + " h=" + img1.height + " w="
img1.width + " ok=") to the imgLoaded func to see whats going on

Feb 20 '06 #6
DDL
This appears to be working!

<script language="javascript1.2" type="text/javascript">

img1 = new Image();
img1.src = '<%=Request.QueryString( "photo" )%>';
img1.onLoad = imgLoaded (this);

function imgLoaded( img ) {
var iWidth = 0;
var iHeight = 0;

iHeight = img1.height;
iWidth = img1.width;

document.write ("<img src='images/photoblank.jpg' border='1' id='photo'
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'<%=Requ est.QueryString(
"photo" )%>', '1', '');
}

</script>
Feb 20 '06 #7
DDL
Spoke too soon... seems to be working in IE - not seen it fail - but FIREFOX
fails most times - I get the 0x0 image... ARGH!

"DDL" <dl****@hotmail.com> wrote in message
news:G5******************************@giganews.com ...
This appears to be working!

<script language="javascript1.2" type="text/javascript">

img1 = new Image();
img1.src = '<%=Request.QueryString( "photo" )%>';
img1.onLoad = imgLoaded (this);

function imgLoaded( img ) {
var iWidth = 0;
var iHeight = 0;

iHeight = img1.height;
iWidth = img1.width;

document.write ("<img src='images/photoblank.jpg' border='1' id='photo'
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'<%=Requ est.QueryString(
"photo" )%>', '1', '');
}

</script>

Feb 20 '06 #8
Hmm

Need to change
img1.onLoad = imgLoaded (this);
because this will call the imgLoaded function straight away then set
onload property to the result of the function

Stick with img1.onload = imgLoaded; as this will make the onload
property a reference to the imgLoaded function and call it later

But you've already tried that and it doesnt work properly so now we're
both stuck!

Can you try the alert function to see whats going on in the imgloaded
function

Feb 20 '06 #9
DDL
got this: but the alert never fires... hmmm - I'll add one up front too...

<script type="text/javascript">

img1 = new Image();
img1.src = '/images/family/Image12.jpg';
img1.onLoad = imgLoaded;

function imgLoaded( event ) {
var iWidth = 0;
var iHeight = 0;

iHeight = img1.height;
iWidth = img1.width;
alert( "src=" + img1.src + " h=" + img1.height + " w=" + img1.width )

document.write ("<img src='images/photoblank.jpg' border='1' id='photo'
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById('photo'),'/images/family/Image12.jpg',
'1', '');
}

</script>
Feb 20 '06 #10
I tested with the script below and the onload handler is case
sensitive, will you change onLoad to onload in your script then see if
that alert is triggered in firefox

<head>
<title>PDC's start</title>
<SCRIPT LANGUAGE = "JavaScript">
function imageLoad()
{
alert("ok");
}

imgTest = new Image();
imgTest.onload = imageLoad;
imgTest.src = "http://localhost/graphic2.jpg";

</SCRIPT> <BODY>hello</BODY></HTML>

Feb 20 '06 #11
Getting closer - DONT try the first Image - I was testing the qstring with
something else...

"tihu" <ti********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I tested with the script below and the onload handler is case
sensitive, will you change onLoad to onload in your script then see if
that alert is triggered in firefox

<head>
<title>PDC's start</title>
<SCRIPT LANGUAGE = "JavaScript">
function imageLoad()
{
alert("ok");
}

imgTest = new Image();
imgTest.onload = imageLoad;
imgTest.src = "http://localhost/graphic2.jpg";

</SCRIPT> <BODY>hello</BODY></HTML>

Feb 21 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2160
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the...
5
2961
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
1
1330
by: KitKat | last post by:
With the help of kind, brilliant folks, I have been working on this program that uses a combo box selection to display six different jpgs. The jps are a time stamp, and the files are located in six...
5
1442
by: Ed Jay | last post by:
I have a switch statement that controls which of several containers is displayed or not. It currently looks like: function showHelp(n) { show('vhelp'); //makes parent container visible switch...
2
2350
by: Poppa Pimp | last post by:
ImageResizer.php Image Resizer PLEASE HELP The URL of the page this is on in my site is http://poppa-pimps-wallpapers.com//ImageResizer.php You can click on browse and get image,but...
36
3068
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it...
7
3918
by: webgyrl | last post by:
Hi, I am helping a musician friend of mine with his profile and I found a cool layout on Nas' MySpace page. I changed some things and re-did the graphics and I basically popped my Image URLS...
0
1885
by: magicofureyes | last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say '''' Your...
5
1396
by: katie smith | last post by:
Here is the program I just started, The problem i am having is I'm trying to get it to load the image file Sand1 with eval(loader) = pygame.image.load(loader) because Loader is euqual to "Sand1" but...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.