Skip to content

Instantly share code, notes, and snippets.

@jamesadney
Created March 4, 2012 08:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesadney/1971332 to your computer and use it in GitHub Desktop.
Save jamesadney/1971332 to your computer and use it in GitHub Desktop.
Load pyglet image from PIL
temp_image = Image.open("picture.png")
raw_image = temp_image.tostring()
image = pyglet.image.ImageData(width, height, 'RGB', raw_image, pitch= -resized_x * 3)
@unreal79
Copy link

unreal79 commented May 9, 2019

In my case this works:

import PIL
temp_image = PIL.Image.open("picture.png")
raw_image = temp_image.tobytes()  # tostring is deprecated
image = pyglet.image.ImageData(temp_image.width, temp_image.height, 'RGBA', raw_image, pitch=-temp_image.width * 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment