Skip to content

Commit

Permalink
Merge pull request #12409 from rtibbles/optional_padding
Browse files Browse the repository at this point in the history
Add optional padding argument to logo tool
  • Loading branch information
rtibbles committed Sep 17, 2024
2 parents b455232 + 192bc8c commit 9eacece
Showing 1 changed file with 15 additions and 2 deletions.
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
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
)

0 comments on commit 9eacece

Please sign in to comment.