Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.38 KB

aspect_ratio_cropping_part_1.md

File metadata and controls

37 lines (27 loc) · 1.38 KB

Description

The aspect ratio of an image describes the proportional relationship between its width and its height. Most video shown on the internet uses a 16:9 aspect ratio, which means that for every pixel in the Y, there are roughly 1.77 pixels in the X (where 1.77 ~= 16/9). As an example, 1080p video with an aspect ratio of 16:9 would have an X resolution of 1920, however 1080p video with an aspect ratio of 4:3 would have an X resolution of 1440.

Write a function that accepts arbitrary X and Y resolutions and converts them into resolutions with a 16:9 aspect ratio that maintain equal height. Round your answers up to the nearest integer.

This kata is part of a series with Aspect Ratio Cropping - Part 2.

Example

374 × 280 pixel image with a 4:3 aspect ratio.

Aspect ratio 4 3 example

500 × 280 pixel image with a 16:9 aspect ratio.

Aspect ratio 16 9 example3

My Solution

def aspect_ratio(x, y)
  [(y.to_f / 9 * 16).ceil, y]
end

Better/Alternative solution from Codewars

def aspect_ratio(x, y)
  [(y * 16 + 8) / 9 , y]
end