import sys
image_path = sys.argv[1]
print(f"Image path argument: {image_path}")


from PIL import Image
import sys
import os

# Get image path from command line argument
image_path = sys.argv[1]

# Open the image
img = Image.open(image_path).convert('RGB')

# Split the image into RGB channels
r, g, b = img.split()

# Shift the red channel: 1 pixels up and 1 pixels right
r = r.transform(
    img.size, 
    Image.AFFINE, 
    (1, 0, 1, 0, 1, -1),
    resample=Image.NEAREST
)

# Shift the green channel: 1 pixels down and 1 pixels left
g = g.transform(
    img.size, 
    Image.AFFINE, 
    (1, 0, -1, 0, 1, 1),
    resample=Image.NEAREST
)

# Merge the channels back
glitched_img = Image.merge('RGB', (r, g, b))

# Save the glitched image
base, ext = os.path.splitext(image_path)
new_path = f"{base}-glitch{ext}"
glitched_img.save(new_path)

print(f"Glitched image saved to {new_path}")
