コード例 #1
0
ファイル: test_image_size.py プロジェクト: paramono/imgc
    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
ファイル: test_image_size.py プロジェクト: paramono/imgc
 def test_parse_raises_on_wrong_type(self):
     size = {}
     with self.assertRaises(TypeError):
         ImageSize.parse(size)
コード例 #8
0
ファイル: test_image_size.py プロジェクト: paramono/imgc
 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)