Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
(PC-11061): upload image - add white background to png images
Browse files Browse the repository at this point in the history
  • Loading branch information
yacine-pc committed Oct 12, 2021
1 parent c9bd18a commit 3c1d1a5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pcapi/utils/image_conversion.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

def standardize_image(image: bytes, crop_params: tuple = None) -> bytes:
crop_params = crop_params or DO_NOT_CROP
raw_image = PIL.Image.open(io.BytesIO(image)).convert("RGB")
raw_image = PIL.Image.open(io.BytesIO(image))
if raw_image.mode == "RGBA":
background = PIL.Image.new("RGB", raw_image.size, (255, 255, 255))
background.paste(raw_image, mask=raw_image.split()[3])
raw_image = background
raw_image = raw_image.convert("RGB")
x_position, y_position, crop_size = crop_params
cropped_image = _crop_image(x_position, y_position, crop_size, raw_image)
resized_image = _resize_image(cropped_image)
Expand Down

0 comments on commit 3c1d1a5

Please sign in to comment.