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)

Modulo magic | greenya | Odin Solutions

package main import "core:fmt" import "core:image" import "core:image/bmp" import "core:image/png" _ :: png main :: proc () { watermark(input_filename="bliss.png", output_filename="result.bmp") } watermark :: proc (input_filename, output_filename: string, limit := 100) { fmt.println("Loading", input_filename) img, err := image.load_from_file(input_filename) assert(err == nil) fmt.println(img) defer image.destroy(img) assert(img.width * img.height == len(img.pixels.buf) / 4) pixels := transmute ([][4] u8) img.pixels.buf[:len(img.pixels.buf)/4] total := img.width * img.height stride := total / limit i, n: int for i < total { o := pixels[i] c := &pixels[i] switch { case n==0 : /**/ case n%2==0 : c.b = byte(round_up_to(int(c.b), 4) % 256) case : c.g = byte(round_up_to(int(c.g), 3) % 256) } fmt.printfln( "num %2d (%d) | idx %8d | pos %4d,%4d | rgb %2x -> %2x", n, n%3, i, i%img.width, i/img.width, o.rgb, c.rgb, ) i += stride n += 1 } fmt.println("Saving", output_filename) err = bmp.save(output_filename, img) assert(err == nil) fmt.println("All done.") } round_up_to :: proc (value, up: int) -> int { for d in 0..<up do if (value+d)%up==0 do return value+d panic("???") }