Skip to content

Instantly share code, notes, and snippets.

@danthegoodman1
Last active March 7, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danthegoodman1/8f40e5e74bf4d08222e3395698aed7da to your computer and use it in GitHub Desktop.
Save danthegoodman1/8f40e5e74bf4d08222e3395698aed7da to your computer and use it in GitHub Desktop.
Exgtract RGB values of each frame from a gif
from PIL import Image
from PIL import GifImagePlugin
im = Image.open('./tenor.gif')
im.seek(0) # changes the frame we are on
# print(im.tell()) # Tells us what frame we are on
p = im.getpalette()
conv = im.convert('RGB')
# print(conv) # converted frame to rgb
width = im.size[0]
height = im.size[1]
count = 0
print("There are {} frames in the gif".format(im.n_frames))
for frame in range(0, im.n_frames):
im.seek(frame)
print("frame", im.tell()) # could print r, but I want to know exactly
for i in range(width):
for x in range(height):
r, g, b = conv.getpixel((i, x))
if r is not 254 and g is not 254 and b is not 254:
count += 1
print(count, "pixels are not white in this gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment