Forum Moderators: open

Message Too Old, No Replies

Dynamically resizing graphics by page res (again....)

Still trying to get this right - SOMEONE here has to be smarter than I am!

         

vkaryl

10:51 pm on Apr 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In goog-searching today for info about forcing graphics in a web page to resize dynamically depending on browser resolution (like one does with a table at width=100% and align=center f'rinstance), I arrived at the script provided by rcjordan at [webmasterworld.com...] Seemed like the perfect fix, since I need to have specific-res pages for 640x480, 800x600, 1024x768, and one for anything higher than that.

While I don't EVER pretend to be brilliant at any of this, I HAVE been writing html and using various scripts and languages since about 1990 (though I'm WAY behind really, since I had to go back to work full-time after 20 years "retired", and now I don't have the time to keep up on things). I can't seem to get rcjordan's apparently nice n simple little script to make any sense, so obviously I'm missing a GOB of stuff. Stuff like: do I need to specify EACH image as var image1, var image2, etc? Shouldn't I need to specify image height somehow, as well as image width? Do I need to put the image pixel-size in "var image1 = '<img src="*.jpg" width="' + image1_width + '">';"? Does this script go in the <head> or the <body>? Does this script go on each page with the pics which one wishes to resize, or on the referring page which redirects the individual's browser to the appropriate page for the browser's resolution? My first assumption when I saw the script was that you simply added it to the referrer page, but the more I looked at it, the less "simple" it seemed....

I'm feeling fairly "simple" myself right now (and I'll no doubt feel totally stupid when one of you points out how simple this REALLY is....) anyway, thanks in advance for any assistance anyone can provide with this.

SinclairUser

10:58 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



If you send me a stick mail perhaps we can work through this problem together and find a solution.

Chris.

ShawnR

1:03 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Chris will obviously discuss the details with you, but I just thought I'd respond to some of the questions, as I have often found the answer to a question by doing a site search and finding a similar problem asked by someone before me. I'd imagine others are the same.

"...do I need to specify EACH image as var image1, var image2, etc?..."

Yes, but if you want them to all be the same size, you don't need to image2_width, etc, you can just say:
var image2 = '<img src="logo2.gif" width="' + image1_width + '">';

"...Shouldn't I need to specify image height somehow, as well as image width? ..."

No. If you leave out the height, it will adjust itself in proportion to the original picture's aspect ratio. If you specify a height, it will distort the aspect ratio (stretch or squash it).

"...Do I need to put the image pixel-size in "var image1 = '<img src="*.jpg" width="' + image1_width + '">';"? ..."

Just copy it verbatim.

"...Does this script go in the <head> or the <body>? ..."

It goes where you want your picture to go. If you want a second picture, put the following two lines, enclosed in script tags, where you want the second picture:

var image2 = '<img src="logo2.gif" width="' + image1_width + '">';
document.write(image2);

(Once you build up some skills, you'd probably make improvements, like and define a function in a separate .js file.)

"...Does this script go on each page with the pics which one wishes to resize, or on the referring page which redirects the individual's browser to the appropriate page for the browser's resolution? ..."

One each page with the pics.

Shawn

SinclairUser

1:08 am on Apr 20, 2003 (gmt 0)

10+ Year Member



Shawn_R,

I just though a bit of offline thought on this point would have been appropriate. Posting the relevant conclusions online - of course! I mean what is the forum for if nor sharing ideas.

Chris.

ShawnR

1:18 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, didn't mean to suggest you weren't sharing...

vkaryl

3:54 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the replies, and so quickly....

I searched on "resize graphics", got 16 results, read each of them through and of course none of them addressed what I was wanting help with. Hence my post of a new topic....

Now, as to the info you so kindly provide, Shawn.... I do hope I'm getting this right, because it seems INFINITELY more complicated that I thought something like this would be. I will obviously play with it tomorrow, and hopefully be bright enough to take what you've given me and get it somewhere close to "right". I'm not sanguine, as you can probably tell....

*shrug* Defining a function? Not until I can quit my day job.... The only programming I do is MUSH softcode....

Anyway, thanks again, guys.

[Um. Anyone have any idea how to "look" at a site at 640x480 when one's monitor/display adaptor doesn't offer a res that low? So far the only idea I've come up with is to set the res on my laptop down that far and see what I can do working back and forth between machines....]

ShawnR

4:40 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"...I searched ..."

Oh, dear, it seems you misunderstood me too. I didn't mean you shouldn't have posted; I just meant that in the future, others might have the same question.

"...it seems INFINITELY more complicated ... I'm not sanguine..."

It is really easy, honest. I hope my post did not make it sound more complex; that was not the intent. Hope you feel fresher in the morning. There are also some guides to getting started here: [webmasterworld.com...]

Shawn

DrDoc

4:53 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how to "look" at a site at 640x480

Well, it's actually much easier than changing the resolution :)

Create a document with the links below. Bookmark each link. Whenever you need to view your site in a different resolution, just "open" the bookmark, and it will resize the browser window for you.

<a href="javascript:window.resizeTo(640,480)">640×480</a>
<a href="javascript:window.resizeTo(800,600)">800×600</a>
<a href="javascript:window.resizeTo(1024,768)">1024×768</a>
<a href="javascript:window.resizeTo(1280,1024)">1280×1024</a>
<a href="javascript:window.resizeTo(1600,1200)">1600×1200</a>

ShawnR

10:01 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's a great idea, Dr Doc. Doesn't work for me with IE, although the general concept does. I think your trick warrants a separate thread, so I'll post what does work for IE in a new thread.

Shawn

vkaryl

3:19 pm on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks again everyone.

I'm going to give it a shot shortly, and I'm going to look for the "what does work for IE" thread....

SLoBBer

7:12 pm on Apr 23, 2003 (gmt 0)

10+ Year Member



lo

i recently came across this prob with my bottom menu
here's how i got around it, may not be the best solution but it works.
I think this is what you may have been looking for?
With the resolutions I'm catering for here I could also add a height change (still might on high res)

<SCRIPT language=JavaScript>
//ooh lovely another javascript :)
//this is to change the bottom right graphic depending on screen res the user is running
//called on load only
function getuserres() {
var userwidth = screen.width
var userheight = screen.height
var reswidthandheight = userwidth + userheight
switch(reswidthandheight) {
case 1792: return "bot_files/bottom_right_end1.gif"; //1024 768
case 2016: return "bot_files/bottom_right_end2.gif"; //1152 864
case 2000: return "bot_files/bottom_right_end3.gif"; //1280 720
case 2048: return "bot_files/bottom_right_end4.gif"; //1280 768
case 2240: return "bot_files/bottom_right_end5.gif"; //1280 960
case 2304: return "bot_files/bottom_right_end6.gif"; //1280 1024
default: return "bot_files/bottom_right_end1.gif"; //1024 768
}
}

//get the user res and display
//document.images["userres"].src=(respic);
//our number is always going to be 26 char if its 1 or 2 or > 3 then set button width accordingly
function loaduserrespic() {
var respic = getuserres();
var sButtonWidth
var iButtonWidth
document.images["userres"].src=(respic);
sButtonWidth = respic.charAt(26)
//alert('our returned char sButtonWidth is '+sButtonWidth);
if (sButtonWidth == 1)
{
iButtonWidth = 110
for (i=1; i<8; i++)
{
document.images["nav0" + i].width=iButtonWidth;
//alert(document.images["nav0" + i].width=iButtonWidth);
}
}

if (sButtonWidth == 2)
{
iButtonWidth = 128
for (i=1; i<8; i++)
{
document.images["nav0" + i].width=iButtonWidth;
//alert(document.images["nav0" + i].width=iButtonWidth);
}
}

if (sButtonWidth >= 3)
{
iButtonWidth = 146
for (i=1; i<8; i++)
{
document.images["nav0" + i].width=iButtonWidth;
//alert(document.images["nav0" + i].width=iButtonWidth);
}
}

}
</SCRIPT>

in body onload=loaduserrespic()

I was also showing a pic on the bottom right to show res, just a gimmick but it all adds to the style ;)

this cycles through 7 buttons, the name of the buttons is nav0x where x will be replaced through the loop

you wont need all the code but hope this helps ;)

L8r
SLoB

vkaryl

3:11 am on Apr 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow. You're LIGHT YEARS ahead of anywhere I might be writing javascript, for sure!

Thanks VERY much. I will try this and see which option seems to work best; I probably won't have the time again to do anything with it all until the weekend but I'll post an update as soon as I know anything - assuming I EVER know anything!

That's one thing I've noticed about this site as opposed to others from which I've attempted to request help: you folks are polite and as helpful as you can be considering the odd things people like me seem to ask. It's truly truly appreciated....