-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel_manipulation.py
More file actions
36 lines (19 loc) · 849 Bytes
/
pixel_manipulation.py
File metadata and controls
36 lines (19 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from PIL import Image
import numpy as np
def encrypt_image(input_image_path, output_image_path, key):
img = Image.open(input_image_path)
img = img.convert('RGB')
img_data = np.array(img)
height, width, channels = img_data.shape
for y in range(height):
for x in range(width):
for c in range(channels):
img_data[y][x][c] ^= key
encrypted_img = Image.fromarray(img_data)
encrypted_img.save(output_image_path)
print(f"Image encrypted and saved as {output_image_path}")
def decrypt_image(input_image_path, output_image_path, key):
encrypt_image(input_image_path, output_image_path, key)
key = 123
encrypt_image('original_image.jpg', 'encrypted_image.jpg', key)
decrypt_image('encrypted_image.jpg', 'decrypted_image.jpg', key)