def dash(sz=(1000, 1000)): gc = GraphicsContextArray(sz) gc.set_fill_color((1.0, 0.0, 0.0, 0.1)) gc.set_stroke_color((0.0, 1.0, 0.0, 0.6)) width = 10 gc.set_line_width(10) phase = width * 2.5 pattern = width * numpy.array((5, 5)) gc.set_line_dash(pattern, phase) gc.set_line_cap(constants.CAP_BUTT) t1 = perf_counter() gc.move_to(10, 10) gc.line_to(sz[0] - 10, sz[1] - 10) gc.line_to(10, sz[1] - 10) gc.close_path() gc.draw_path() t2 = perf_counter() with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file(fid.name, resist_width="weak", resist_height="weak") tot_time = t2 - t1 print("time:", tot_time) return image
def test_fromfile_png_rgba(self): # basic smoke test - assume that kiva.image does the right thing path = os.path.join(data_dir, 'PngSuite', 'basi6a08.png') image = Image.from_file(path) self.assertEqual(image.data.shape, (32, 32, 4)) self.assertEqual(image.format, 'rgba32')
def test_fromfile_png_rgb(self): # basic smoke test - assume that kiva.image does the right thing path = os.path.join(data_dir, "PngSuite", "basn2c08.png") image = Image.from_file(path) self.assertEqual(image.data.shape, (32, 32, 3)) self.assertEqual(image.format, "rgb24")
def compiled_path(): # Creating the compiled path star_points = [ (-20, -30), (0, 30), (20, -30), (-30, 10), (30, 10), (-20, -30), ] path = CompiledPath() path.move_to(*star_points[0]) for pt in star_points[1:]: path.line_to(*pt) locs = [ (100, 100), (100, 300), (100, 500), (200, 100), (200, 300), (200, 500), ] gc = GraphicsContext((300, 600)) gc.set_stroke_color((0, 0, 1, 1)) gc.draw_path_at_points(locs, path, STROKE) with tempfile.NamedTemporaryFile(suffix=".jpg") as fid: gc.save(fid.name) image = Image.from_file(fid.name, resist_width="weak", resist_height="weak") return image
def gradient(): gc = GraphicsContext((500, 500)) gc.scale_ctm(1.25, 1.25) draw(gc) with tempfile.NamedTemporaryFile(suffix=".png") as fid: gc.save(fid.name, file_format="png") image = Image.from_file( fid.name, resist_width="weak", resist_height="weak" ) return image
def rect(): gc = GraphicsContext((500, 500)) gc.clear() gc.rect(100, 100, 300, 300) gc.draw_path() with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file(fid.name, resist_width="weak", resist_height="weak") return image
def ellipse(): gc = GraphicsContext((300, 300)) gc.set_alpha(0.3) gc.set_stroke_color((1.0, 0.0, 0.0)) gc.set_fill_color((0.0, 1.0, 0.0)) gc.rect(95, 95, 10, 10) gc.fill_path() draw_ellipse(gc, 100, 100, 35.0, 25.0, pi / 6) with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file(fid.name, resist_width="weak", resist_height="weak") return image
def simple(): gc = GraphicsContext((499, 500)) gc.set_fill_color((0, 0, 0)) gc.rect(99, 100, 300, 300) gc.draw_path() # directly manipulate the underlying Numeric array. # The color tuple is expressed as BGRA. gc.bmp_array[:99, :100] = (139, 60, 71, 255) with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file( fid.name, resist_width="weak", resist_height="weak" ) return image
def stars(): gc = GraphicsContext((500, 500)) gc.translate_ctm(250, 300) add_star(gc) gc.draw_path() gc.translate_ctm(0, -100) add_star(gc) gc.set_fill_color((0.0, 0.0, 1.0)) gc.draw_path(constants.EOF_FILL_STROKE) with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file( fid.name, resist_width="weak", resist_height="weak" ) return image
def _create_component(self): file_path = rect() image = Image.from_file(file_path, resist_width='weak', resist_height='weak') container = ConstraintsContainer(bounds=[500, 500]) container.add(image) ratio = float(image.data.shape[1]) / image.data.shape[0] container.layout_constraints = [ image.left == container.contents_left, image.right == container.contents_right, image.top == container.contents_top, image.bottom == container.contents_bottom, image.layout_width == ratio * image.layout_height, ] return container
def simple(): gc = GraphicsContext((100, 100)) gc.clear() gc.set_line_cap(constants.CAP_SQUARE) gc.set_line_join(constants.JOIN_MITER) gc.set_stroke_color((1, 0, 0)) gc.set_fill_color((0, 0, 1)) gc.rect(0, 0, 30, 30) gc.draw_path() with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file( fid.name, resist_width="weak", resist_height="weak" ) return image
def _create_window(self): path = os.path.join(THIS_DIR, 'deepfield.jpg') image = Image.from_file(path, resist_width='weak', resist_height='weak') container = ConstraintsContainer(bounds=[500, 500]) container.add(image) ratio = float(image.data.shape[1])/image.data.shape[0] container.layout_constraints = [ image.left == container.contents_left, image.right == container.contents_right, image.top == container.contents_top, image.bottom == container.contents_bottom, image.layout_width == ratio*image.layout_height, ] return Window(self, -1, component=container)
def _create_component(self): path = os.path.join(THIS_DIR, "deepfield.jpg") image = Image.from_file(path, resist_width="weak", resist_height="weak") container = ConstraintsContainer(bounds=[500, 500]) container.add(image) ratio = float(image.data.shape[1]) / image.data.shape[0] container.layout_constraints = [ image.left == container.contents_left, image.right == container.contents_right, image.top == container.contents_top, image.bottom == container.contents_bottom, image.layout_width == ratio * image.layout_height, ] return container
def stars(): gc = GraphicsContext((500, 500)) with gc: gc.set_alpha(0.3) gc.set_stroke_color((1.0, 0.0, 0.0)) gc.set_fill_color((0.0, 1.0, 0.0)) for i in range(0, 600, 5): with gc: gc.translate_ctm(i, i) gc.rotate_ctm(i * pi / 180.0) add_star(gc) gc.draw_path() gc.set_fill_color((0.5, 0.5, 0.5, 0.4)) gc.rect(150, 150, 200, 200) gc.fill_path() with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file(fid.name, resist_width="weak", resist_height="weak") return image