Last active
August 29, 2015 14:18
Image manipulation in Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame, sys | |
from pygame.locals import * | |
pygame.init() | |
grey = (150, 150, 150) | |
lite_grey = (220, 220, 220) | |
blue = (80, 144, 154) | |
dark_blue = (0,50,77) | |
lite_blue = (143,220,236) | |
display_surface = pygame.display.set_mode((900,948)) | |
display_surface.fill(grey) | |
image = pygame.image.load("image_before.png").convert() | |
for x in range(900): | |
for y in range(948): | |
color_temp = image.get_at((x,y)) | |
temp_int = color_temp[0] + color_temp[1] + color_temp[2] | |
integer = (max(color_temp[0], color_temp[1], color_temp[2]) + temp_int//2//3) | |
if integer < 70: | |
image.set_at((x,y),dark_blue) | |
elif integer < 100: | |
image.set_at((x,y),blue) | |
elif integer < 130: | |
image.set_at((x,y),lite_blue) | |
else: | |
image.set_at((x,y),lite_grey) | |
pygame.image.save(image, 'image_after.png') | |
while True: | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
pygame.quit() | |
sys.exit() | |
display_surface.blit(image, (0,0)) | |
pygame.display.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment