Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional padding argument to logo tool #12409

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions build_tools/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# The default input size is based off the current size of the Kolibri logo SVG
def convert_svg_to_image(
svg_file_path, output_file_path, input_size=200, final_size=None
svg_file_path, output_file_path, input_size=200, final_size=None, padding=None
):
ext = os.path.splitext(output_file_path)[1].lower()
temp_png_file = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
Expand All @@ -34,6 +34,11 @@ def convert_svg_to_image(

# Determine the dimensions for a square based on the cropped image
max_dim = max(img_cropped.size)

if padding:
padding = int(padding) / 100
Copy link
Member

@AllanOXDi AllanOXDi Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None blocking, but I wonder if we could add some additional error handling to ensure that the padding value is a valid percentage (i.e. between 0 and 100). i.e. ensure that the padding value is within this range, and raising an error if it is not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely could - as this was developer only code, I was not as thorough.

max_dim += int(max_dim * padding)

square_size = (max_dim, max_dim)

# Create a new square image with a transparent background
Expand Down Expand Up @@ -76,7 +81,15 @@ def convert_svg_to_image(
help="Optional final size to resize the output image to a square of this size.",
default=None,
)
parser.add_argument(
"--padding",
type=int,
help="Optional add this percentage of padding around the bounding box.",
default=None,
)

args = parser.parse_args()

convert_svg_to_image(args.svg_file, args.image_file, final_size=args.size)
convert_svg_to_image(
args.svg_file, args.image_file, final_size=args.size, padding=args.padding
)