Does any have example of js code to resize images?

L

LORD BROWN

Was wondering if any one knew of any code, or could point me to a site that
has an example of resizing images using JavaScript (have a site were many of
the image are not the same size and want to create a 'standard' size for
display on a page)? Thanks your help would be much appreciated. JEB
 
I

Ivo

LORD BROWN said:
Was wondering if any one knew of any code, or could point me to a site that
has an example of resizing images using JavaScript (have a site were many of
the image are not the same size and want to create a 'standard' size for
display on a page)? Thanks your help would be much appreciated. JEB

If what you descibe is all you want, you don't need javascript.

<img src="worm.gif" width=200 height=500>
<!-- this image is only 2 by 5 but the page has its own ideas -->
<img src="Empire_state_building.jpg" width=200 height=500>
<!-- You will wonder why this nice little photo takes an hour to load.
Well, it 's a 2000 by 5000 monster straight from my digital camera. -->
 
T

The Plankmeister

Was wondering if any one knew of any code, or could point me to a site
that
has an example of resizing images using JavaScript (have a site were many of
the image are not the same size and want to create a 'standard' size for
display on a page)? Thanks your help would be much appreciated. JEB


You don't need Javascript to achieve that... just use the height and width
attributes of the IMG tag.
However.... Let's say for example that you have a 6MB .jpg file that's 3000
pixels high by 2500 pixels wide. If you want this to appear as if it's only
50 high by 45 wide, you could just do this: <img src="blah.jpg" height="50"
width="45"> but it will still have to download the whole image first. Which
is a bad thing. Javascript can only work on the client side so can only deal
with objects already in the browser (i.e. downloaded images)
I think what you mean to do is perhaps have something on the server-side
that dynamically resizes the images before they are sent to the browser...
Then your 6MB monster jpg would only perhaps be 10k. And that's a whole
other kettle of fish!

HTH.

P.
 
T

Tony

LORD BROWN said:
Was wondering if any one knew of any code, or could point me to a site that
has an example of resizing images using JavaScript (have a site were many of
the image are not the same size and want to create a 'standard' size for
display on a page)? Thanks your help would be much appreciated. JEB

From The JavaScript Source:
Resize any image by clicking the image and dragging it to the desired size.

http://javascript.internet.com/miscellaneous/image-resizer-drag-and-drop.html



<!-- TWO STEPS TO INSTALL IMAGE RESIZER - DRAG AND DROP:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function resizeImage(evt,name){
newX=evt.x
newY=evt.y
eval("document."+name+".width=newX")
eval("document."+name+".height=newY")
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

Click and drag on the image to resize it.
<p>
<img src="http://javascript.internet.com/img/headerlogo.gif"
width="150" height="58" name="image1"
ondrag="resizeImage(event,'image1')">


<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 0.98 KB -->
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,093
Messages
2,570,607
Members
47,226
Latest member
uatas12

Latest Threads

Top