Download the Guru IA app

Android and iOS

Foto de perfil

Fabricio

SENT BY THE APP
Estudos Gerais11/23/2024

from PIL import Image # Abrir a imagem enviada pelo usuár...

from PIL import Image

Abrir a imagem enviada pelo usuário

input_path = "/mnt/data/file-LHq1wWA7BwNK2h9j7brr4P" output_path = "/mnt/data/squared_image.jpg"

Carregar a imagem

img = Image.open(input_paimg.sizeth)

Tornar a imagem quadrada mantendo o conteúdo centralizado

width, height = img.size if width != height: size = max(width, height) new_img = Image.new("RGB", (size, size), (255, 255, 255)) # Fundo branco new_img.paste(img, ((size - width) // 2, (size - height) // 2)) else: new_img = img

Salvar a nova imagem quadrada

new_img.save(output_path) output_path

Send your questions through the App
Equipe Meu Guru

Do you prefer an expert tutor to solve your activity?

  • Receive your completed work by the deadline
  • Chat with the tutor.
  • 7-day error guarantee