Skip to content

Instantly share code, notes, and snippets.

@euske
Created November 2, 2019 00:16
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 euske/1cbf6d33c5a0f99bf803fde60fd92b26 to your computer and use it in GitHub Desktop.
Save euske/1cbf6d33c5a0f99bf803fde60fd92b26 to your computer and use it in GitHub Desktop.
Change an image gamma with Pygame
import pygame
def set_gamma(img, gamma):
buf = img.get_buffer()
gmap = bytes( min(255, int(255*pow(i/255, gamma))) for i in range(256) )
buf.write(buf.raw.translate(gmap), 0)
return
img = pygame.image.load("in.jpg")
set_gamma(img, 0.5)
pygame.image.save(img, "out.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment