示例#1
0
    def test_parse_processes_iterables(self, parse_tuple):
        size = (800, 600,)
        ImageSize.parse(size)
        self.assertEqual(parse_tuple.call_count, 1)
        parse_tuple.assert_called_with(size, None)

        size = [800, 600]
        ImageSize.parse(size)
        self.assertEqual(parse_tuple.call_count, 2)
        parse_tuple.assert_called_with(size, None)
示例#2
0
    def test_parse_processes_iterables(self, parse_tuple):
        size = (
            800,
            600,
        )
        ImageSize.parse(size)
        self.assertEqual(parse_tuple.call_count, 1)
        parse_tuple.assert_called_with(size, None)

        size = [800, 600]
        ImageSize.parse(size)
        self.assertEqual(parse_tuple.call_count, 2)
        parse_tuple.assert_called_with(size, None)
示例#3
0
文件: __init__.py 项目: paramono/imgc
    def resize_image(self, src, dst):
        print("resizing")
        pattern = self.size
        quality = self.quality

        im = Image.open(src)

        new_size = ImageSize.parse(pattern, image=im)
        print('new_size:', new_size)
        im = im.resize(new_size, Image.BICUBIC)


        if os.path.splitext(dst)[1][1:].strip().lower() not in IMAGE_JPG:
            im.save(dst)
            print("saving non-jpeg %s" % dst)
        else:
            # quality supported by jpegs only
            im.save(dst, 'JPEG', quality=quality)
            print("saving jpeg %s" % dst )
        self.imgs_done += 1
        # self.print_status(dst)

        print ("processed")
        try:
            self.on_image_processed(self.imgs_done, self.imgs_total)
            print ("method called")
        except AttributeError:
            self.print_status(dst)
示例#4
0
    def resize_image(self, src, dst):
        # print("resizing")
        pattern = self.size
        quality = self.quality

        try:
            im = Image.open(src)

            new_size = ImageSize.parse(pattern, image=im)
            # print('new_size:', new_size)
            im = im.resize(new_size, Image.BICUBIC)

            if os.path.splitext(dst)[1][1:].strip().lower() not in IMAGE_JPG:
                im.save(dst)
            else:
                # quality supported by jpegs only
                im.save(dst, 'JPEG', quality=quality)

            print("saved: %s" % dst)
            self.imgs_done += 1
        except OSError as err:  # e.g. file is corrupt and cannot be open
            print('ERROR')
            print(err)

        try:
            self.on_image_processed(self.imgs_done, self.imgs_total)
            print("method called")
        except AttributeError:
            self.print_status(dst)
示例#5
0
 def test_parse_raises_on_wrong_type(self):
     size = {}
     with self.assertRaises(TypeError):
         ImageSize.parse(size)
示例#6
0
 def test_parse_processes_strings(self, parse_string):
     size = '800x600'
     ImageSize.parse(size)
     self.assertEqual(parse_string.call_count, 1)
     parse_string.assert_called_with(size, None)
示例#7
0
 def test_parse_raises_on_wrong_type(self):
     size = {}
     with self.assertRaises(TypeError):
         ImageSize.parse(size)
示例#8
0
 def test_parse_processes_strings(self, parse_string):
     size = '800x600'
     ImageSize.parse(size)
     self.assertEqual(parse_string.call_count, 1)
     parse_string.assert_called_with(size, None)