Yekong's Blog

A blog about my experiences and thoughts.

Image Magic

Click to challenge

Description

Thanks to the hints, it really helped a lot. Just rearrage image pixels and learn a new library.

Solution

If you tried to open the image, you will get a long bar image.

One of the hint reveals that the original image width is 304 pixels, so try to get the height.

Now just try to rearrage all the pixels to their correct positions.

Code

from PIL import Image

img = Image.open("out copy.jpg")
data_arr = img.load()
# img = img.resize((27968, 1))
# rezise(width, height)

new_img = Image.new("RGB", (304, 93))
new_pix = new_img.load()

# Don't care about the variables naming
step = 0 # Actually is column/height
current_height = 0 # Actually is row/width
for i in range(img.width):
    if step == 92:
        current_height += 1
        step = 0

    new_pix[current_height, step] = data_arr[i, 0]
    step += 1

new_img.save("new_image.jpg")

img = Image.open("new_image.jpg")
img.show()