All problems
Letterbox Resize
Problem
Compute the letterbox geometry that fits an h x w image into a target x target square.
Scale by the smaller ratio, round the new height and width, then set top = (target - new_h) // 2 and left = (target - new_w) // 2. Return [new_h, new_w, top, left].
Test cases
case 1
in: [100,200,256]
expected: [128,256,64,0]
case 2
in: [50,100,64]
expected: [32,64,16,0]
case 3
in: [100,100,64]
expected: [64,64,0,0]
case 4
in: [300,400,256]
expected: [192,256,32,0]
Starter codePython
def letterbox_size(h, w, target):
# Your code here
pass4 test cases · run your code against them in the editor