All SolutionsAll Solutions

🖼️

Image Watermark

Week 27, 2026

Python - Pillow Lib & Pixel Manipulation | BMC | Python Solutions

# this challenge was hell... from PIL import Image def getImageList(imgPath: str) -> list[(int, int, int)]: img = Image.open(imgPath).convert("RGB") pixel_list = list(img.getdata()) return pixel_list def changeBliss(imgPath: str, width: int, height: int): src = Image.open(imgPath).convert("RGB") x = list(src.getdata()) point = 0 for i in range(0, (width*height), int(width*height/100)): r = x[i][0] g = x[i][1] b = x[i][2] if point == 0: if r == 255: r = 0 elif point % 2 == 0: b = ((b + 3) // 4) * 4 % 256 # ceil B up to nearest multiple of 4, wrapping 256 -> 0 | Mr. P's hint :p else: g = ((g + 2) // 3) * 3 % 256 # ceil G up to nearest multiple of 3 (never wraps, 255 is a multiple of 3) point += 1 x[i] = ( r, # RED g, # GREEN b # BLUE ) img = Image.new('RGB', src.size) img.putdata(x) img.save(f"{imgPath.split('.')[0]}-watermark.png") def compareTwoImg(imgList1: list[(int, int, int)], imgList2: list[(int, int, int)]) -> list[int]: # both imgList1 and imgList2 must have same {ROW x COL} diff = [] for i in range(len(imgList1)): a1, b1, c1 = imgList1[i] a2, b2, c2 = imgList2[i] if (a1 - a2) + (b1 - b2) + (c1 - c2) != 0: diff.append( [ i, # index [a1, a2], # R1 - R2 [b1, b2], # G1 - G2 [c1, c2] # B1 - B2 ] ) return diff def cmp(img1: str, img2: str) -> None: x = getImageList(img1) y = getImageList(img2) z = compareTwoImg(x, y) for i in z: print(i) print(len(z)) # main changeBliss("bliss.png", 1920, 1080)