473,778 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to resize <IMG> width absolute and height relative ?

As well known for <IMG ...> tags in web pages a width and a height attribute can be
applied. What I want to do now is to fix the width for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.

The height should be adjusted proportional so that the resulting thumbnail is not distorted.
But as far as I know there is no such attribute like

<IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....

How can I solve this problem ?

As a second best solution I could accept if I could write percentage values:
<IMG SRC=..... WIDTH=50% HEIGHT=50%>

but this doesn't work too.

Wladimir

Jul 20 '05 #1
9 72124
"Wladimir Borsov" <wl*******@gmx. net> schrieb im Newsbeitrag
news:c7******** *****@news.t-online.com...
As well known for <IMG ...> tags in web pages a width and a height attribute can be applied. What I want to do now is to fix the width for ALL the images on my web page to exactly lets say 70 pixel regardless how big the originals are.

The height should be adjusted proportional so that the resulting thumbnail is not distorted. But as far as I know there is no such attribute like

<IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....

How can I solve this problem ?


Just don't write a height attribute, then AFAIK user agents should scale the
image proportionally.

But actually if this is applied to several images you should prefer to scale
them at the server side, otherwise you send much too much data to the
client.

HTH
Markus
Jul 20 '05 #2
Wladimir Borsov <wl*******@gmx. net>
(news:c7******* ******@news.t-online.com) wrote:
As well known for <IMG ...> tags in web pages a width and a height
attribute can be applied. What I want to do now is to fix the width
for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.

The height should be adjusted proportional so that the resulting
thumbnail is not distorted. But as far as I know there is no such
attribute like

<IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....

How can I solve this problem ?
<img width="70" SRC="..."> :)
As a second best solution I could accept if I could write percentage
values:
<IMG SRC=..... WIDTH=50% HEIGHT=50%>

but this doesn't work too.

Wladimir


Jul 20 '05 #3
"Wladimir Borsov" <wl*******@gmx. net> wrote in
comp.infosystem s.www.authoring.html:
As well known for <IMG ...> tags in web pages a width and a height attribute can be
applied. What I want to do now is to fix the width for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.

The height should be adjusted proportional so that the resulting thumbnail is not distorted.
But as far as I know there is no such attribute like

<IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....

How can I solve this problem ?


In some (most?) browsers, leave off the height and it will be
adjusted proportionally.

But this is a bad thing to do. Why impose the penalty on the user of
downloading a larger picture, then not let her see it? If you want
your pictures to be 70px wide, crop them yourself before uploading.

<img> width and height should always match the actual width and
height of the image.

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #4
While the city slept, Wladimir Borsov <wl*******@gmx. net> feverishly typed:
As well known for <IMG ...> tags in web pages a width and a height
attribute can be applied. What I want to do now is to fix the width
for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.

The height should be adjusted proportional so that the resulting
thumbnail is not distorted. But as far as I know there is no such
attribute like

<IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....


You can use a server-side solution, such as PHP to do the maths. Off the top
of my head, if you know the original image width and heght (if not, no
problems as you can get them using PHP) something like the following should
work;

<? php

$desiredwidth = 70;
$originalwidth = 100; // replace originalwidth and originalheight with
whatever the image dimensions are...
$originalheight = 200; // ... or find a better way of getting them!

$ratio = $originalwidth / $desiredwidth;
$desiredheight = $originalheight / $ratio;

print("<img src=\"whatever. jpg\" width=\"$desire dwidth\"
height=\"$desir edheight\" alt=\"whatever\ ">\n");
?>

I haven't thoroughly checked this, so the maths may be wrong! But it still
shows a way to do it.

Remember, though, that if an original image is smaller than 70 pixels wide,
then this may result in distortion of the image as it will be stretched.
Remember also that this is a bad way to make thumbnails of large images, as
the full size image file still has to be loaded, regardless of how small you
are making it appear on the screen.

Hope that helps,
Nige

--
Nigel Moss.

Email address is not valid. ni***@nigenetDO G.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
Jul 20 '05 #5
On Mon, 3 May 2004 14:11:20 +0200, wl*******@gmx.n et (Wladimir Borsov)
wrote:

: As well known for <IMG ...> tags in web pages a width and a height attribute can be
: applied. What I want to do now is to fix the width for ALL the images on my web page
: to exactly lets say 70 pixel regardless how big the originals are.
:
: The height should be adjusted proportional so that the resulting thumbnail is not distorted.
: But as far as I know there is no such attribute like
:
: <IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....
:
: How can I solve this problem ?
Have only width=70. Remove height altogether. You'll get what you want.

Sid

Jul 20 '05 #6
Wladimir Borsov wrote:
What I want to do now is to fix the width for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.

<snip>

I'm not sure about browser compatibility, this works on my IE6, Netscape
7.1, Firefox 0.8:

function resizepics(w,h) {
var p = document.getEle mentsByTagName( 'img');
for (var i=0; i<p.length; i++){
p[i].style.width=w;
p[i].style.height=h ;
}
}

Mike

Jul 20 '05 #7
"nice.guy.n ige" <ni********@dea dspam.com> schrieb im Newsbeitrag
news:c7******** ****@ID-112325.news.uni-berlin.de...
While the city slept, Wladimir Borsov <wl*******@gmx. net> feverishly typed:
As well known for <IMG ...> tags in web pages a width and a height
attribute can be applied. What I want to do now is to fix the width
for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.

The height should be adjusted proportional so that the resulting
thumbnail is not distorted. But as far as I know there is no such
attribute like

<IMG SRC=...... WIDTH=70 HEIGHT="Adjust proportional to Width"> ....
You can use a server-side solution, such as PHP to do the maths. Off the

top of my head, if you know the original image width and heght (if not, no
problems as you can get them using PHP) something like the following should work;

<? php

$desiredwidth = 70;
$originalwidth = 100; // replace originalwidth and originalheight with
whatever the image dimensions are...
$originalheight = 200; // ... or find a better way of getting them!

$ratio = $originalwidth / $desiredwidth;
$desiredheight = $originalheight / $ratio;

print("<img src=\"whatever. jpg\" width=\"$desire dwidth\"
height=\"$desir edheight\" alt=\"whatever\ ">\n");
?>

I haven't thoroughly checked this, so the maths may be wrong! But it still
shows a way to do it.

Remember, though, that if an original image is smaller than 70 pixels wide, then this may result in distortion of the image as it will be stretched.
Remember also that this is a bad way to make thumbnails of large images, as the full size image file still has to be loaded, regardless of how small you are making it appear on the screen.


If you suggest the serverside solution I would suggest to use PHP to
actually resize the image file, not just the HTML code...

--
Markus
Jul 20 '05 #8

"mscir" <ms***@access4l ess.com.net.org .uk> wrote in message
news:10******** *****@corp.supe rnews.com...
Wladimir Borsov wrote:
What I want to do now is to fix the width for ALL the images on my web page to exactly lets say 70 pixel regardless how big the originals are. <snip>

I'm not sure about browser compatibility, this works on my IE6, Netscape
7.1, Firefox 0.8:


.... when Javascript is enabled.

function resizepics(w,h) {
var p = document.getEle mentsByTagName( 'img');
for (var i=0; i<p.length; i++){
p[i].style.width=w;
p[i].style.height=h ;
}
}

Mike


Jul 20 '05 #9
Wladimir Borsov wrote:
As well known for <IMG ...> tags in web pages a width and a height attribute can be
applied. What I want to do now is to fix the width for ALL the images on my web page
to exactly lets say 70 pixel regardless how big the originals are.


Resize the images with a editing app. Client-side resizing will not
exactly enhance the quality of the image. (to put it mildly) Especially
images with repeating structures are prone to moire effects if you do.

--

/*************** *************** *************** *************** *************** *
JotM aka Jaap van der Heide
Remove ".XXXnospam XXX" for a valid return address
Please reply to a news message in the group where the message was posted
*************** *************** *************** *************** *************** */

Jul 20 '05 #10

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

Similar topics

5
12306
by: homecurr | last post by:
I am writing a tool to generate html and have a problem with the <img> tag. The tool generates something like "<img src="...">". At the time the html is generated, the tool does not know the actual image size, but I do want to resize any image so that their width and height will both be smaller than 100. I also want to keep the iamge width/height ration so the image looks "normal". If I use <img src="..." width=100 height=100> the image...
15
122153
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width: 123px; height: 456px;" alt="">
4
2593
by: Jim Moe | last post by:
Hello, Mozilla (suite and Firefox) ignore the height and width attributes of <img> when the image itself is unavailable (404); only enough space is allocated for the alt text. Is this expected behavior for Standards mode? -- jmm dash list (at) sohnen-moe (dot) com (Remove .AXSPAMGN for email)
10
3319
by: News | last post by:
I am trying to be able to manipulate the width and height of an <img> but do not seem to be able. "Yes", I know the JavaScript will "not" manip anything, which is ok. I simply do not know how to capture the width or height. Once I can do that I can manipulate them. Here is the HTML for the <img> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)"> <img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
4
1324
by: johanvdv | last post by:
Hello, I'm building a website which contains a floor plan of my house. I want to indicate if some lights in my house are on or off. I thought I found a good way to do it with filter.lights.addPoint (IE only) but this has a limit of 10, which is not enough. Has anyone has an idea how to archive this ? How can I add images to an existing image on a certain position ?
1
4628
by: Carl | last post by:
Hi all I have a javascript function that drags and drops an element (ie img) into a container (ie bordered div). The function works and returns the element and and container. My next step is to center the element in the container if the user is sloppy with positioning it. I can only test this on IE6 and IE5.5 and it fails. It positions the element too much right and low. Here is the function: function SnapToContainer(Container,El) {
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
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 we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.