473,406 Members | 2,378 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,406 software developers and data experts.

Image resize problem Javascript

Hi I have a problem with the code im using to resize an image to fit it within a fixed size cell in a table. The code is supposed to resize the image and retain its aspect ratio. But it does not seem to be resizing it . The example can be seen here www.climbthemunros.co.uk/test_page2.htm

My code is shown below . Can anyone see what im doing wrong ?
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <title>Ben Nevis - Image Gallery</title>
  6. <script type="text/javascript">
  7.  
  8.  
  9.  
  10.  
  11. function bigpic(file)
  12. {
  13.  
  14.         var main = document.getElementById("MAINPIX");
  15.  
  16.        main.style.height = "auto";
  17.        main.style.width = "auto";
  18.  
  19.       main.src = (file)
  20.  
  21. }
  22.  
  23.  
  24. function fixSize(image)
  25. {
  26.  
  27.     var w = image.width *2;
  28.     var h = image.height *2;
  29.  
  30.     if ( w > 395 )
  31.     {
  32.  
  33.          h = Math.floor( h * 395 / w );
  34.          w = 395;
  35.     }
  36.  
  37.     if ( h > 286 )
  38.     {
  39.          w = Math.floor( w * 286 / h );
  40.          h = 286;
  41.     }
  42.  
  43.     image.width = w;
  44.     image.height = h;
  45.    image.style.left = Math.floor( (395 - w ) / 2 ) + "px";
  46.     image.style.top = Math.floor( (286 - h ) / 2 ) + "px";
  47.     image.style.visibility = "visible";
  48. }
  49. </script>
  50. </head>
  51.  
  52. <body>
  53.  
  54. <div style="position: relative; height: 280px; width: 395px; overflow: hidden">
  55.     <img id="MAINPIX" style="position: absolute;" onload="fixSize(this);"> </div>
  56. <a onclick="bigpic('http://www.climbthemunros.co.uk/test4.jpg')">next </a>
  57. <a onclick="bigpic('http://www.climbthemunros.co.uk/test3.jpg')">previous</a>
  58.  
  59. </body>
  60.  
  61. </html>
  62.  
Mar 18 '10 #1
1 2160
gits
5,390 Expert Mod 4TB
tested it with chromium ... it only does something when clicking the next/previous 'buttons'? ... then it shows images ... but i don't get what the problem should be exactly. no JavaScript error occurs and the image-height is fixed ... shouldn't it be that way? what does '... But it does not seem to be resizing it ...' mean here? for me it seems ok ... which browser do you use?

kind regards
Mar 20 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Weng kin | last post by:
Hi everyone, I have a problem trying to load an image without the image resizing itself to fit into the window. My simple javascript is as follows: function viewImage(filename) { features =...
8
by: Abs | last post by:
Hi! I have an image inside a DIV box with its dimensions specified. The problem is that I don't know the dimensions of the image beforehand, therefore the image grows outside the box if it's...
20
by: http://links.i6networks.com | last post by:
I need to display pictures, but only as large as AxB. If it is smaller than AxB, then I will display it in the original size, if it is larger than AxB, I will resize it. However, if the size is...
8
by: Michael Satterwhite | last post by:
I'm opening a page that has a single image on it. I'd like to resize the window containing the image to the size of the image (slightly larger OK, not smaller). The width isn't a problem, but the...
6
by: ACaunter | last post by:
Hi there, I was wondering if there is a way to allow the user to resize an image by clicking and drawing on of the four corners of the image.. thanks -- AdamPC@hotmail.com
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
8
by: Robert S | last post by:
I am writing an image viewer. I want to be able to resize the image so that it always fits within a window of given height and width. I've tried a couple of these from the web, but the don't...
6
by: Bob Bedford | last post by:
Hi all, I've a classic upload form where people may select images on their computer to send on my website. Since this is done by people not very confortable with computers, some sent pictures...
3
by: kayahr | last post by:
Hi there, I have a strange problem in Internet Explorer (IE6 and IE7). I'm writing a JavaScript application which allows the user to edit a photo composition. So when the user selects a photo then...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.