Ho ottenuto un logo quadrato e ho bisogno di round_corner esso, cercato per un po 'e ottenuto il codice di seguito "lavoro":come arrotondare un logo senza sfondo bianco (trasparente?) Usando pil?
def round_corner_jpg(image, radius):
"""generate round corner for image"""
mask = Image.new('RGB', image.size)
#mask = Image.new('RGB', (image.size[0] - radius, image.size[1] - radius))
#mask = Image.new('L', image.size, 255)
draw = aggdraw.Draw(mask)
brush = aggdraw.Brush('black')
width, height = mask.size
draw.rectangle((0,0,width,height), aggdraw.Brush('white'))
#upper-left corner
draw.pieslice((0,0,radius*2, radius*2), 90, 180, None, brush)
#upper-right corner
draw.pieslice((width - radius*2, 0, width, radius*2), 0, 90, None, brush)
#bottom-left corner
draw.pieslice((0, height - radius * 2, radius*2, height),180, 270, None, brush)
#bottom-right corner
draw.pieslice((width - radius * 2, height - radius * 2, width, height), 270, 360, None, brush)
#center rectangle
draw.rectangle((radius, radius, width - radius, height - radius), brush)
#four edge rectangle
draw.rectangle((radius, 0, width - radius, radius), brush)
draw.rectangle((0, radius, radius, height-radius), brush)
draw.rectangle((radius, height-radius, width-radius, height), brush)
draw.rectangle((width-radius, radius, width, height-radius), brush)
draw.flush()
del draw
return ImageChops.add(mask, image)
poi ho salvato l'oggetto immagine restituita, tuttavia ha sfondo bianco in un angolo like this Come posso eliminare lo sfondo bianco o renderlo invisibile? Grazie in anticipo ~
EDIT: ecco il codice da Fraxel, grazie ~
def add_corners(im, rad):
circle = Image.new('L', (rad * 2, rad * 2), 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
alpha = Image.new('L', im.size, "white")
w, h = im.size
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
im.putalpha(alpha)
return im
if __name__ == '__main__':
im = Image.open('1.jpg')
im = add_corners(im, 100)
im.save('out.png')`
Sono così sorry..I bisogno della forma immagine da un'ellisse non rettangolo, cioè. la roba da scrivere fuori dalla foto e @fraxel, posso ancora vedere l'angolo bianco nella foto che hai elaborato per me
grazie, ma ha ancora l'angolo bianco sullo sfondo. Controlla questo [collegamento] (http://www.flickr.com/photos/[email protected] N03/7485468218/in/photostream) per vedere il problema, e ho bisogno che l'angolo rosa sia invisibile, nel tuo caso l'angolo bianco (non riesci a vederlo qui visto che è bianco, lo stesso colore della pagina web) .. Spero tu capisca cosa intendo – bdictator
@bdictator - per favore pubblica il tuo codice completo. e stai usando il mio codice e sto salvando come png? – fraxel
sì, sto usando il tuo codice, controlla il mio codice aggiunto – bdictator