FFitLumen
Workflows

Coding workflows · Aspect-fit pixel boxes

03
Built around your work

A concrete starting point

Fit an image into a pixel box using integer dimensions from 1 through 1000000. Test portrait, landscape and odd padding, rejecting a subpixel result and rounding the scaled size down before centering.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Aspect-fit pixel boxes

A concrete starting point
def fit_box(image_width, image_height, box_width, box_height):
    values = (image_width,image_height,box_width,box_height)
    if any(type(v) is not int or not 1 <= v <= 1000000 for v in values):
        raise ValueError("dimensions 1 through 1000000")
    if image_width*box_height > image_height*box_width:
        width, height = box_width, image_height*box_width//image_width
    else:
        width, height = image_width*box_height//image_height, box_height
    if not width or not height: raise ValueError("subpixel result")
    return (box_width-width)//2, (box_height-height)//2, width, height

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗