Fix transparent AI avatar cutout and woven Mento logo mark.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
from PIL import Image
|
||||
|
||||
src = r"C:\Users\Mahdi\.cursor\projects\e-projeha-crm\assets\mento-ai-avatar-transparent.png"
|
||||
dst = r"e:\projeha\crm\apps\web\public\brand\mento-ai-avatar.png"
|
||||
|
||||
img = Image.open(src).convert("RGBA")
|
||||
pixels = img.load()
|
||||
w, h = img.size
|
||||
cx, cy = w / 2, h / 2
|
||||
radius = min(w, h) * 0.42
|
||||
|
||||
for y in range(h):
|
||||
for x in range(w):
|
||||
r, g, b, a = pixels[x, y]
|
||||
if r > 245 and g > 245 and b > 245:
|
||||
pixels[x, y] = (r, g, b, 0)
|
||||
continue
|
||||
# leftover dark plate far from character
|
||||
if r < 40 and g < 70 and b < 80 and a > 200:
|
||||
dist = ((x - cx) ** 2 + (y - cy) ** 2) ** 0.5
|
||||
if dist > radius:
|
||||
pixels[x, y] = (r, g, b, 0)
|
||||
|
||||
bbox = img.getbbox()
|
||||
if bbox:
|
||||
img = img.crop(bbox)
|
||||
pad = 12
|
||||
padded = Image.new("RGBA", (img.width + pad * 2, img.height + pad * 2), (0, 0, 0, 0))
|
||||
padded.paste(img, (pad, pad), img)
|
||||
img = padded
|
||||
|
||||
img.save(dst, "PNG")
|
||||
px = img.load()
|
||||
print("saved", dst, img.size)
|
||||
print("corner alpha", px[0, 0][3], px[img.width - 1, 0][3])
|
||||
Reference in New Issue
Block a user