Aspect ratio
The aspect ratio of a geometric shape is the ratio of its sizes in different dimensions. For example, the aspect ratio of a rectangle is the ratio of its longer side to its shorter side – the ratio of width to height, when the rectangle is oriented as a "landscape".
표준 화면비율
- 1:1
- 1.33:1 (4:3)
- 1.77:1/1.78:1 (16:9)
- 1.85:1 (37:20)
- 2:1 (18:9)
- 2.39:1 (21:9)
기타 화면비율
- 1.25:1 (5:4)
- 1.37:1
- 1.41:1
- 1.44:1
- 1.5:1 (3:2)
- 1.6:1 (16:10)
- 1.66:1 (5:3)
- 1.73:1 (루트 3:1)
- 1.9:1
- 2.055:1 (18.5:9)
- 2.111:1 (19:9)
- 2.167:1 (19.5:9)
- 2.222:1 (20:9)
화면비율 변경 방식
방식 | 이름 |
양 옆에 검은 박스 추가 | 필러박스 |
가로로 늘리기 | 스트레치 |
위아래 자르기 | 확대 |
위 아래 검은 박스 추가 | 레터박스 |
세로로 늘리기 | 아나모픽 |
양 옆 자르기 | 팬&스캔 |
Calculator in Python
original_width = coco_object['images']['width']
original_height = coco_object['images']['height']
width = input_width # The size you want to change.
height = input_height # The size you want to change.
if width >= 1 and height >= 1:
resize_width = width
resize_height = height
elif width <= 0 and height >= 1:
resize_height = height
if aspect_ratio:
resize_width = int(original_width*height/original_height)
else:
resize_width = original_width
elif width >= 1 and height <= 0:
resize_width = width
if aspect_ratio:
resize_height = int(original_height*width/original_width)
else:
resize_height = original_height
else:
assert width <= 0 and height <= 0
resize_width = original_width
resize_height = original_height
JavaScript version
import {TypeException} from "@/exceptions";
export interface Size {
width?: number;
height?: number;
}
export function aspectRatio(original: Size, destination: Size) {
const ow = original.width;
const oh = original.height;
if (typeof ow !== 'number') {
throw new TypeException('The `original.width` argument is not a numeric type.');
}
if (typeof oh !== 'number') {
throw new TypeException('The `original.height` argument is not a numeric type.');
}
const dw = destination.width;
const dh = destination.height;
if (dw && dh) {
return {width: dw, height: dh} as Size;
} else if (!dw && dh) {
return {width: ow * dh / oh, height: dh} as Size;
} else if (dw && !dh) {
return {width: dw, height: oh * dw / ow} as Size;
} else {
return {width: ow, height: oh} as Size;
}
}
CSS version
- CSS, object-fit: cover
- CSS, aspect-ratio