Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
javascript math: what is the height of the image

What is the css height of the image if the width is for example: 3px?

original image height is 400px; original image width is 800px;

what I've tried is:

convert the 3px to a percentage of the original image width:

function perwVal(v){
return 100 * v / iow; //img orig width
}

function perhVal(v){
return   v / 100 * ioh; // img original height
}

var imgwidthPerc = perwVal(3);
var imgheightPerc = perhVal(imgwidthPerc);

// not correct the height is off

any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You get the ratio of the width vs. height:

const ratio = originalWidth / originalHeight;

and then to find the width for a different height:

const newWidth = newHeight * ratio;

In your example:

const originalHeight = 800;
const originalWidth = 400;
const ratio = originalWidth / originalHeight;
const newHeight = 3;
const newWidth = newHeight * ratio;
console.log(newWidth);

But note Sebastian's point that you may not need it, you may be able to use CSS's aspect-ratio.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!