Created
May 4, 2022 16:21
-
-
Save TomAugspurger/e76e1366a3dadcf3578edac779bd4d3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import skimage | |
import requests | |
import urllib.request | |
import io | |
from PIL import Image, ImageChops | |
import numpy as np | |
def make_hero(url): | |
f = urllib.request.urlopen(url) | |
f = io.BytesIO(f.read()) | |
img = Image.open(f).crop((0, 0, 720, 184)).resize((1800, 460)).convert("RGBA") | |
mask = np.zeros(img.size, dtype="uint8") | |
a = 600 | |
b = 1000 | |
mask[:a, :] = 255 | |
mask[a:b] = np.linspace(255, 0, b - a).reshape(-1, 1) | |
mask = Image.fromarray(mask.T, mode="L") | |
img.paste((0, 0, 0, 255), (0, 0), mask) | |
return img | |
Author
TomAugspurger
commented
May 4, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment