Skip to content

Instantly share code, notes, and snippets.

@SeyedAbdollahi
SeyedAbdollahi / negative.py
Created December 5, 2021 20:05
Example of negative of an image with Python and Pygame
import pygame
img = pygame.image.load('F:\input1.jpg')
W, H = img.get_width(), img.get_height()
for x in range(W):
for y in range(H):
color = pygame.Surface.get_at(img, (x,y))
color = ~color
pygame.Surface.set_at(img, (x,y), color)
@SeyedAbdollahi
SeyedAbdollahi / adjusting_contrast.py
Last active December 5, 2021 19:38
Example of adjusting contrast of an image with Python and Pygame
import pygame
img = pygame.image.load('F:\input.jpg')
W, H = img.get_width(), img.get_height()
contrast = int(input())
F = (259 * (contrast + 255)) / (255 * (259 - contrast))
def fix_color(color):
if color > 255:
return 255
@SeyedAbdollahi
SeyedAbdollahi / adjusting_brightness.py
Last active December 5, 2021 19:38
Example of adjusting brightness of an image with Python and Pygame
import pygame
img = pygame.image.load('F:\input.jpg')
W, H = img.get_width(), img.get_height()
brightness = int(input())
def fix_color(color):
if color > 255:
return 255
elif color < 0: