def crop_image_GUI (label, x1, y1, x2, y2): '''Implement the crop_image function from img_manip.''' #Clear all the temp pics in front of the current pic current_pic global temp_label global current_pic temp_label = temp_label[0:current_pic+1] #Implement the function crop_image label.picture = img_manip.crop_image(label.picture, x1, y1, x2, y2) #Keep a copy of the current pic for the functions Undo and Redo temp_label.append(label.picture) current_pic += 1 #update the label update_label(label)
def test_crop_image(): '''Test the function crop_image in img_manip.''' new_pic = create_pic(4, 4) new_pic_cropped = img_manip.crop_image(new_pic, 1, 1, 2, 2) #Test if the colour of each pixel in new_pic is equal to the colour of the #corresponding pixel in new_pic_cropped. If not, the boolean cropped is #made False. cropped = True for x in range(2): for y in range(2): new_pic_pix = media.get_pixel(new_pic, x + 1, y + 1) new_pic_cropped_pix = media.get_pixel(new_pic_cropped, x, y) col1 = media.get_color(new_pic_pix) col2 = media.get_color(new_pic_cropped_pix) if col1 != col2: cropped = False assert cropped, \ "crop_image failed to crop the picture correctly."