def test_add_colors(): img = Image(10, 10, preset_colors='BW') assert img.get_color_names() == ['transparent', 'black', 'white'] img.add_color('light grey', (220, 220, 220)) assert img.get_color_names() == [ 'transparent', 'black', 'white', 'light grey' ] assert img.get_color_index('light grey') == 3 img.draw_rectangle((2, 2), (7, 7), fill_color='light grey') img.save(outfile('test_image_grey.bmp')) with pytest.raises(ValueError): # color doesn't exist img.draw_rectangle((2, 2), (7, 7), fill_color='red')
def test_array_set(): arr = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]], dtype=np.uint8, order='f') img = Image(arr.shape[0], arr.shape[1], preset_colors='web') img.set_data(arr) img.save(outfile('test_image_array1.bmp')) print img.get_color_names() for i in range(4): for j in range(3): print img.get_pixel_color((i, j)), print img.get_pixel_value((i, j)) for y in range(img.height): for x in range(img.width): assert arr[x, y] == img.get_pixel_value((x, y))