I'm working on a webapp that edits an image and part of it includes from a canvas on html I get a selection area which I save as a png example image below
next step is to get the x,y positions of the selection area so I know where only to apply an effect the code looks like this
pixels = img.load()
if cropped:
x, y = position['left'], position['top']
else:
x, y = 0, 0
img_width, img_height = 0, 0
matches = []
counter = 0
for _ in range(img.width * img.height):
if img_width == img.width:
img_width = 0
img_height += 1
counter += 1
pixel = pixels[img_width, img_height]
if pixel != (0, 0, 0, 0):
matches.append([img_width+y, img_height+x])
img_width += 1
if matches:
filename = random_filename(extension='.pickle')
with open(filename, 'wb') as f:
# Pickle the 'data' dictionary using the highest protocol available.
pickle.dump(matches, f, pickle.HIGHEST_PROTOCOL)
this gets the cells and saves it into a pickle.
However when I apply an effect to these cells there's a "halo effect" where a line of selection is a distance away from the main selection area
I made sure it wasn't the apply effect that had an issue, since it only uses the specified area it can't be.
I also went a step further and used one of the selection area pixels to reconstruct a png file to see if it has the issue (which it should)
In [1]: from PIL import Image
In [14]: new = Image.new('RGB', (600, 399))
In [15]: import pickle
In [16]: pickle_file = open('pickle_cells/qPxsEaw7wcQR5YWK9iZrb6r.pickle', 'rb')
In [17]: cells = pickle.load(pickle_file)
In [18]: pickle_file.close()
In [20]: cells[0]
Out[20]: [259, 117]
In [22]: for cell in cells:
...: new.putpixel([cell[0], cell[1]], (50, 50, 50))
...:
In [23]: new.save('test.png')
In [24]:
this creates this image which shows the same error




