Python + Pillow + Images2Gif - incorrect color of GIF frames -


i'm using following code add watermark animated gif images. problem gif frames except first 1 have incorrect colors in result. know how fix color of frames? thank you.

def add_watermark(in_file, watermark_file, watermark_position, watermark_ratio, out_file, quality=85):    img = image.open(in_file)    watermark_layer = image.new('rgba', img.size, (0,0,0,0))    watermark_img = image.open(watermark_file).convert('rgba')    watermark_img.thumbnail((img.size[0]/watermark_ratio, 1000), image.antialias)    alpha = watermark_img.split()[3]    alpha = imageenhance.brightness(alpha).enhance(0.95)    watermark_img.putalpha(alpha)    watermark_layer.paste(watermark_img, count_watermark_position(img, watermark_img, watermark_position))    frames = images2gif.readgiffrompil(img, false)    frames_out = []    frame in frames:        frames_out.append(image.composite(watermark_layer, frame, watermark_layer))    images2gif.writegif(out_file, frames_out, duration=0.5) 

to complete example, provide code of helper function:

def count_watermark_position(img, watermark, position):    if position == 'right_bottom':       return img.size[0] - watermark.size[0], img.size[1] - watermark.size[1]    if position == 'center':       return (img.size[0] - watermark.size[0])/2, (img.size[1] - watermark.size[1])/2    if position == 'left_bottom':        return 0, img.size[1] - watermark.size[1]    if position == 'left_top':        return 0, 0    if position == 'right_top':       return img.size[0] - watermark.size[0], 0    raise attributeerror('invalid position') 

source code of images2gif 've used - modified little bit make work pillow. see comment @ begining of source code.


Comments