/    Sign up×
Community /Pin to ProfileBookmark

Auto resize script doesn’t work.

Would you help me with this script please? It is [I]supposed[/I] to auto resize images and allow the viewer to click the image for a full size version. It is in the head of my HTML.
I have searched the forum and tried the w3c tutorial and others to no avail.

[code=php]

<SCRIPT LANGUAGE=”JavaScript”>
<!–

// Set the Maximum Width and Height
var maxImageWidth = 350;
var maxImageHeight = 350;

function resizeImage(thisimage) {
if (thisimage.height > thisimage.width) {
// check and modify height if needed
if (thisimage.height > maxImageHeight) {
thisimage.height = maxImageHeight;
thisimage.style.cursor=’hand’;
}
} else {
// check and modify width if needed
if (thisimage.width > maxImageWidth) {
thisimage.width = maxImageWidth;
thisimage.style.cursor=’hand’;
}
}
}

// End –>
</script>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroSep 13.2004 — This script is meant to be used on images smaller than the max sizes listed, and enlarge them, not the other way around, right? Then change the red > signs into < signs:
<i>
</i>function resizeImage(thisimage) {
if (thisimage.height &gt; thisimage.width) {
// check and modify height if needed
if (thisimage.height [COLOR=RED]&gt;[/COLOR] maxImageHeight) {
thisimage.height = maxImageHeight;
thisimage.style.cursor='hand';
}
} else {
// check and modify width if needed
if (thisimage.width [COLOR=RED]&gt;[/COLOR] maxImageWidth) {
thisimage.width = maxImageWidth;
thisimage.style.cursor='hand';
}
}
}

Copy linkTweet thisAlerts:
@ClaymoreauthorSep 13.2004 — [i]Originally posted by HaganeNoKokoro [/i]

[B]This script is meant to be used on images smaller than the max sizes listed, and enlarge them, not the other way around, right? Then change the red > signs into < signs:



...

[/QUOTE]


Sorry, should have been clearer. :o It's purpose is to shrink large images to the max specified and maintain aspect ratio.

BTW, There is no size specified in my IMG tags.



Here is a link to the page in question on my site, The second pic is huge.

http://www.armoredplastic.000k.net/reviews.html
Copy linkTweet thisAlerts:
@HellspireSep 13.2004 — This code appears redundant... how can you have a comparison about height to width (laughs....) Lets try to correct

<script language='javascript'><!--

var maxImageWidth = 350;

var maxImageHeight = 350;

function resizeImage(thisimage){

if(thisimage.width > maxImageWidth){thisimage.width = maxImageWidth;}

if(thisimage.height > maxImageHeight){thisimage.height = maxImageHeight;}

thisimage.style.cursor='hand';

}

//--></script>

ohhhhh.... After writing ths script for you I looked at your old code and found your problem (potentially)

if (thisimage.height > thisimage.width) { you were comparing height to width... and the WRONG width i might add =p, use my script above... dont bother with the other.... its flawed.

Note also, that your function is designed to only handle one image at a time, I suggest that you have another function which will grab all elements that are images, and run them through a while() function, onload()

Good luck ?
Copy linkTweet thisAlerts:
@ClaymoreauthorSep 14.2004 — Thanks for the help, think i'm on the right track now.

The height/width comparsion was an attempt at getting it to resize based on the largest dimension whether it is height or width.
×

Success!

Help @Claymore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...