Spaces:
Sleeping
Sleeping
jk commited on
Commit ·
3240d92
1
Parent(s): 9c329bc
Updated output.bmp and deleted test.bmp
Browse filesFiles changed (3)
- test.bmp → assets/test.bmpRenamed
- output.bmp
- pixelate.pyAdded+75
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475from PIL import Image
# Open the original .bmp fileimage = Image.open("assets/test.bmp")
width, height = image.size
# Print width and height of the imageprint(f"Size: {image.size}")
# Save each pixel of the image in a listpixels = list(image.getdata())print(pixels)print("------------------" + str(len(pixels)))
# Return pixel list seperated in rowsdef split_list_to_row(list, n): for i in range(0, len(list), n): yield list[i : i + n]
# Split the list of pixels into rowspixels_rows = list(split_list_to_row(pixels, width))
print(pixels_rows)print("------------------" + str(len(pixels_rows)))
# Create a list for every element of a element in pixels_rows and return a list of lists# Split the list of pixels into rowspixels_rows = list(split_list_to_row(pixels, width))
# Create a list for every element of a element in pixels_rows and return a list of listspixels_columns = []
for i in range(0, len(pixels_rows)): for x in range(0, len(pixels_rows[i])): print(pixels_rows[i][x]) pixels_rows[i][x] = [pixels_rows[i][x]] print(pixels_rows[i][x])
print(pixels_rows)print("------------------" + str(len(pixels_rows)))
# Convertscaled_list = pixels_rowsfor i in range(0, len(pixels_rows)): for x in range(0, len(pixels_rows[i])): for y in range(0, len(pixels_rows[i][x])): scaled_list[i][x].insert(0, pixels_rows[i][x][y]) scaled_list[i][x].insert(0, pixels_rows[i][x][y]) scaled_list[i][x].append(pixels_rows[i][x][y]) scaled_list[i][x].append(pixels_rows[i][x][y])
# Convert the list of of seperated lists into a list of tuplesnew_list = []for i in range(0, len(scaled_list)): for x in range(0, len(scaled_list[i])): for y in range(0, len(scaled_list[i][x])): new_list.append(scaled_list[i][x][y])
print(new_list)print("------------------" + str(len(new_list)))
# Create a new image with increased width to accommodate the additional pixelnew_image = Image.new("RGB", (width * 5, height * 5))
# Print width and height of the imageprint(f"Size: {new_image.size}")
# Copy the original image to the new imagenew_image.putdata(new_list)
# Save the modified image as a new .bmp filenew_image.save("output.bmp")test.bmp → assets/test.bmpRenamed


output.bmp


pixelate.pyAdded+75