Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:05:47+00:00 2026-06-14T10:05:47+00:00

I am resizing an image in JavaScript based on the current viewport size. No

  • 0

I am resizing an image in JavaScript based on the current viewport size. No media queries and other such things, JS all the way, and no static sizes for elements.

So basically it looks something like this:

    var computedHeight = viewport.height * someRatio;
    var image = goog.dom.createDom('img', {
        'src': 'the.link.to.the.image',
        'height': computedHeight + 'px',
        'width': 'auto'
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:05:48+00:00Added an answer on June 14, 2026 at 10:05 am

    As the others said, you can’t get the size before the image has been inserted into the document.

    But you can calculate the size on your own.

    When the image has been loaded, you may access the original size of the image. Based on this it’s not very difficult to calculate the scaled size:

        var image = goog.dom.createDom('img', {
        'src': 'the.link.to.the.image',
        'height': computedHeight + 'px',
        'width': 'auto',
        'onload':function(){
          alert('width:'+
                Math.floor((this.naturalWidth*this.height)/this.naturalHeight)+
                '\nheight:'+this.height);        
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the effect that I need: http://www.agilepartners.com/blog/2005/12/07/iphoto-image-resizing-using-javascript/ Is there any jQuery plugin doing
I'm working on a JavaScript image resizing feature which rely on the IE only
This is driving me crazy, so... When resizing image to small thumbnail, resulting image
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I am using the iPhone camera to capture an image and them resizing and
Is it possible to resize a background image on load using javascript? I don't
is there any javascript library for resizing the images according to browser window sizes
I'm trying to create a thumbnail image on the client side using javascript and
I have a user-uploaded image pulled from the database that I am resizing smaller
I've read several helpful answers in re. image resizing using PHP and max-height etc.:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.