def test_three_vertical(self): """Three vertical cuts""" sub_dir = 'test_three_vertical' self._create_empty_dir(sub_dir) dwg = self._scratch_drawing() layer = dwg.add(dwg.g()) g1 = layer.add(dwg.g()) simple_path_down_center = g1.add( dwg.path('M 0 0 L 250 0 L 200 300 L 250 960 L 0 960')) g2 = layer.add(dwg.g()) simple_path_down_center = g2.add( dwg.path('M 0 0 L 450 0 L 480 200 L 450 960 L 0 960')) g3 = layer.add(dwg.g()) simple_path_down_center = g3.add( dwg.path('M 0 0 L 650 0 L 680 400 L 650 960 L 0 960')) clips = Clips(svgstring=dwg.tostring(), clips_dir=os.path.join(self.test_dir, sub_dir), size=(1280, 960)) scissors = Scissors(clips, 'wild-daisy.jpg', os.path.join(self.test_dir, sub_dir)) scissors.cut()
def test_one_vertical(self): """A single vertical cut""" sub_dir = 'test_one_vertical' self._create_empty_dir(sub_dir) dwg = self._scratch_drawing() layer = dwg.add(dwg.g()) g = layer.add(dwg.g()) #g['class'] = 'clip' simple_path_down_center = g.add( dwg.path('M 0 0 L 250 0 L 200 300 L 250 960 L 0 960')) clips = Clips(svgstring=dwg.tostring(), clips_dir=os.path.join(self.test_dir, sub_dir), size=(1280, 960)) scissors = Scissors(clips, 'wild-daisy.jpg', os.path.join(self.test_dir, sub_dir)) scissors.cut()
def test_three_and_three(self): """smaller Three vertical cut and three horizontal""" sub_dir = 'test_smaller_three_and_three' self._create_empty_dir(sub_dir) dwg = self._scratch_drawing() layer1 = dwg.add(dwg.g()) g1 = layer1.add(dwg.g()) simple_path_down_center = g1.add( dwg.path('M 0 0 L 250 0 L 200 300 L 250 960 L 0 960')) g2 = layer1.add(dwg.g()) simple_path_down_center = g2.add( dwg.path('M 0 0 L 450 0 L 480 200 L 450 960 L 0 960')) g3 = layer1.add(dwg.g()) simple_path_down_center = g3.add( dwg.path('M 0 0 L 650 0 L 680 400 L 650 960 L 0 960')) # layer 2 layer2 = dwg.add(dwg.g()) g1 = layer2.add(dwg.g()) simple_path = g1.add( dwg.path('M 0 0 L 1280 0 L 1280 200 L 600 360 L 0 200')) g2 = layer2.add(dwg.g()) simple_path = g2.add( dwg.path('M 0 0 L 1280 0 L 1280 400 L 300 560 L 0 500')) g3 = layer2.add(dwg.g()) simple_path = g3.add( dwg.path('M 0 0 L 1280 0 L 1280 600 L 900 760 L 0 600')) clips = Clips(svgstring=dwg.tostring(), clips_dir=os.path.join(self.test_dir, sub_dir), size=(256, 192)) #wild-daisy-small.jpg = 256x192 scissors = Scissors(clips, 'wild-daisy-small.jpg', os.path.join(self.test_dir, sub_dir)) scissors.cut()
def cut(): parser = OptionParser(usage="%prog --dir path/to/dir --svg path/to/svgfile [options] path/to/image", description="cut an image by specifying the clips svg") parser.add_option("--dir", "-d", action="store", type="string", help="Set the directory to store the clip files in.",) parser.add_option("--svg", "-s", action="store", type="string", help="Set the svg file.",) #TODO: should just get the size from the image parser.add_option("--width", action="store", type="int", default=1280, help="width of image ",) parser.add_option("--height", action="store", type="int", default=960, help="height of image ",) (options, args) = parser.parse_args() if not args and not (options.dir and options.svg): parser.error("Must set a directory and svg file with an image") print 'snip, snip' mydir = options.dir clips = Clips(svgfile=options.svg, clips_dir=mydir, size=(options.width, options.height)) #TODO: could probably use the scissors on multiple images scissors = Scissors(clips, args[0], mydir) scissors.cut()