473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic resizing of images

I need to be able to set EITHER document.imageName.width OR
document.imageName.height to a specific value and then have the other
property set to it's default. For instance, if I was going to
hard-code all these images, some would look like <img src=blah
width=100> and some would look like <img src=blah2
height=100>. How do I "leave off" the second sizing parameter from
javascript. I've tried width='', width=0, width=null - none of these
work as they make the image have zero width.
Jul 20 '05 #1
3 1534
Mike wrote:
I need to be able to set EITHER document.imageName.width OR
document.imageName.height to a specific value and then have the other
property set to it's default. For instance, if I was going to
hard-code all these images, some would look like <img src=blah
width=100> and some would look like <img src=blah2
height=100>. How do I "leave off" the second sizing parameter from
javascript. I've tried width='', width=0, width=null - none of these
work as they make the image have zero width.


I'm not sure what the problem is, if you don't want to change a particular
dimension of a particular image, just don't change it:

<body onload="setTestImageHeight();">
<script type="text/javascript">
function setTestImageHeight() {
document.images['testImage'].height = 200;
}
</script>
<img src="100by100.gif" name="testImage" />

After loading this page, the test image will be 200 pixels high and 100
pixels wide (assuming the browser supports dynamically resized images).

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2
@SM
Mike a ecrit :

I need to be able to set EITHER document.imageName.width OR
document.imageName.height to a specific value and then have the other
property set to it's default. For instance, if I was going to
hard-code all these images, some would look like &lt;img src=blah
width=100&gt; and some would look like &lt;img src=blah2
height=100&gt;. How do I "leave off" the second sizing parameter from
javascript. I've tried width='', width=0, width=null - none of these
work as they make the image have zero width.


understood anything !

function resizeImage(img,width,height){
if(document.images){
i=document.images[img];
alert('image default width = '+i.width+
'\nimage default height = '+i.height);
if(width!='' && i.width!=width) i.width=width;
else
if(height!='' && i.height!=height) i.height=height;
}}

<img src="asm.gif" name="i04" width=50>
<img src="asm.gif" name="i02">
<p><a href="javascript:resizeImage('i04',500,'');">exo 1</a>
<p><a href="javascript:resizeImage('i04','',150);">exo 2</a>
<p><a href="javascript:resizeImage('i02','',50);">exo 3</a>

--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #3
@SM wrote:

<--snip-->
<p><a href="javascript:resizeImage('i04',500,'');">exo 1</a>
<p><a href="javascript:resizeImage('i04','',150);">exo 2</a>
<p><a href="javascript:resizeImage('i02','',50);">exo 3</a>


Perhaps you have not read the group FAQ? If you haven't, then you
should. URL is in my signature.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4

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

Similar topics

2
by: Alex Hopson | last post by:
I'm using the code below to loop through some images and resize each image twice, once to create a thumbnail and once to create a small image. The page stops loading around the 38th image out of...
10
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger...
6
by: Robert J. O'Hara | last post by:
I'm one of those people who practices what some consider "dull" and others consider "elegantly conservative" page design. I appreciate good traditional typography and standards-compliant liquid...
5
by: Robert J. O'Hara | last post by:
For some time I've made use of the max-width property in CSS to cause my pages to appear as a centered block against a contrasting background. This works well in new browsers (Mozilla, etc.) and...
5
by: Jim | last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick) is a processor intensive exercise. I'm setting up a site where users will be uploading up to 10 images along with the details...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
3
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.