Покраска ванной комнаты водоэмульсионной краской фото дизайн

from PIL import Image
import requests
import io
from io import BytesIO
from wand.image import Image as wi
from wand.color import Color

def paint_bathroom_wall(image_url, paint_color):
«»»Paints the bathroom wall in the image with the given paint color.

Args:
image_url (str): The URL of the image to paint.
paint_color (str): The color to paint the wall.

Returns:
Image: The painted image.
«»»

# Download the image from the given URL.
response = requests.get(image_url)
image = Image.open(BytesIO(response.content))

# Convert the image to the Wand image format.
with io.BytesIO() as output:
image.save(output, format=»png»)
wand_image = wi(file=output)

# Create a mask of the wall in the image.
wall_mask = wand_image.clone()
wall_mask.crop(200, 200, wand_image.width — 200, wand_image.height — 200)
wall_mask.equalize()
wall_mask.contrast(0.5)
wall_mask.threshold(128)

# Paint the wall in the image with the given paint color.
wand_image.composite(wall_mask, 0, 0)
wand_image.fill(Color(paint_color))

# Convert the Wand image back to the PIL image format.
with io.BytesIO() as output:
wand_image.save(filename=output)
pil_image = Image.open(BytesIO(output.getvalue()))

return pil_image

Читать статью  Самые красивые ванные комнаты плитка дизайн фото

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *