Refine desktop onboarding and NSIS branding

This commit is contained in:
Esdras Renan 2025-10-19 00:01:27 -03:00
parent 36f34d81d3
commit 5f7dccff71
6 changed files with 100 additions and 20 deletions

View file

@ -123,15 +123,16 @@ def parse_png(path: Path):
return width, height, image
def resize_with_letterbox(image, width, height, target_w, target_h, background):
if width == target_w and height == target_h:
def resize_with_letterbox(image, width, height, target_w, target_h, background, scale_factor=1.0):
if width == target_w and height == target_h and abs(scale_factor - 1.0) < 1e-6:
return image, width, height
bg_r, bg_g, bg_b = background
scale = min(target_w / width, target_h / height)
scale = max(scale, 1 / max(width, height)) # avoid zero
scaled_w = max(1, int(round(width * scale)))
scaled_h = max(1, int(round(height * scale)))
base_scale = min(target_w / width, target_h / height)
base_scale *= scale_factor
base_scale = max(base_scale, 1 / max(width, height)) # avoid zero / collapse
scaled_w = max(1, int(round(width * base_scale)))
scaled_h = max(1, int(round(height * base_scale)))
output = bytearray(target_w * target_h * 4)
# Fill background
@ -142,9 +143,9 @@ def resize_with_letterbox(image, width, height, target_w, target_h, background):
offset_y = (target_h - scaled_h) // 2
for y in range(scaled_h):
src_y = min(height - 1, int(round(y / scale)))
src_y = min(height - 1, int(round(y / base_scale)))
for x in range(scaled_w):
src_x = min(width - 1, int(round(x / scale)))
src_x = min(width - 1, int(round(x / base_scale)))
src_idx = (src_y * width + src_x) * 4
dst_idx = ((y + offset_y) * target_w + (x + offset_x)) * 4
output[dst_idx : dst_idx + 4] = image[src_idx : src_idx + 4]
@ -206,6 +207,12 @@ def main():
parser.add_argument("output", type=Path)
parser.add_argument("--width", type=int, help="Target width (px)")
parser.add_argument("--height", type=int, help="Target height (px)")
parser.add_argument(
"--scale",
type=float,
default=1.0,
help="Optional multiplier applied to the fitted image size (e.g. 0.7 adds padding).",
)
parser.add_argument(
"--background",
type=str,
@ -218,7 +225,9 @@ def main():
width, height, image = parse_png(args.input)
if args.width and args.height:
bg = tuple(int(args.background[i : i + 2], 16) for i in (0, 2, 4))
image, width, height = resize_with_letterbox(image, width, height, args.width, args.height, bg)
image, width, height = resize_with_letterbox(
image, width, height, args.width, args.height, bg, max(args.scale, 0.05)
)
rgb = blend_to_rgb(image)
write_bmp(args.output, width, height, rgb)
except Exception as exc: # noqa: BLE001
@ -228,4 +237,3 @@ def main():
if __name__ == "__main__":
main()