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

381
Views
Resize an image to aspect ratio 16:9

I'm trying to resize the uploaded image to 16:9. I've been trying all day and this is the best I've done so far.

const resizeResult = await manipulateAsync(
  uploadResult.uri,
  [
    {
      resize:
        uploadResult.width > uploadResult.height
          ? { height: 900 }
          : { width: 1600 },
    },
    {
      crop: {
        width: 1600,
        height: 900,
        originX:
          uploadResult.width > uploadResult.height
            ? (uploadResult.height - uploadResult.width) / 2
            : (uploadResult.width - uploadResult.height) / 2,
        originY: 0,
      },
    },
  ],
  { compress: 0.7, format: SaveFormat.JPEG }
);

Unfortunately, this resizes/crops the 1800x1200 image to 1350x900, not 1600x900.

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

0

I think you just have to calculate and cap the size of the image using its aspect ratio.

const ratio = uploadResult.width / uploadResult.height;

let newWidth = ratio * 900;
let newHeight = 900;

if (ratio > 0) {
    newWidth = 1600;
    newHeight = 1600 / ratio;
}

const resizeResult = await manipulateAsync(
  uploadResult.uri,
  [
    {
      resize: { height: newHeight, width: newWidth }
    }
  ],
  { compress: 0.7, format: SaveFormat.JPEG }
);
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!