documents

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

rand-noise-image.py (658B)


      1 
      2 import random
      3 from PIL import Image
      4 
      5 def change_random_pixels(image_path, output_path, iterations, color_hex="#2e1b1e"):
      6     color = tuple(int(color_hex.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
      7     
      8     with Image.open(image_path) as img:
      9         img = img.convert("RGB")
     10         pixels = img.load()
     11         width, height = img.size
     12         
     13         for _ in range(iterations):
     14             x = random.randint(0, width - 1)
     15             y = random.randint(0, height - 1)
     16             pixels[x, y] = color
     17             
     18         img.save(output_path)
     19 
     20 if __name__ == "__main__":
     21     change_random_pixels("input.png", "output.png", 200000)