4 from PIL
import Image
as PilImage
6 from manga_py
import fs
7 from manga_py
.manga_image
import MangaImage
9 root_path
= path
.dirname(path
.realpath(__file__
))
12 ['/files/img1.jpg', '/temp/img1.jpg'],
13 ['/files/img2.png', '/temp/img2.png'],
14 ['/files/img3.jpg', '/temp/img3.jpg'],
15 ['/files/img4.jpg', '/temp/img4.jpg'],
16 ['/files/img5.png', '/temp/img5.png'],
17 ['/files/img6.gif', '/temp/img6.gif'],
18 ['/files/img7.webp', '/temp/img7.webp'],
22 class TestImages(unittest
.TestCase
):
24 def test_manual_crop(self
):
25 for file in files_paths
:
26 fs
.unlink(root_path
+ file[1])
28 image
= PilImage
.open(root_path
+ file[0])
32 img
= MangaImage(root_path
+ file[0])
33 img
.crop_manual((10, 0, image
.size
[0], image
.size
[1]), root_path
+ file[1])
36 cropped_image
= PilImage
.open(root_path
+ file[1])
37 cropped_sizes
= cropped_image
.size
40 self
.assertTrue((sizes
[0] - cropped_sizes
[0]) == 10)
42 def test_manual_crop_with_offsets(self
):
43 for file in files_paths
:
44 fs
.unlink(root_path
+ file[1])
46 image
= PilImage
.open(root_path
+ file[0])
50 img
= MangaImage(root_path
+ file[0])
51 img
.crop_manual_with_offsets((10, 0, 0, 0), root_path
+ file[1])
54 cropped_image
= PilImage
.open(root_path
+ file[1])
55 cropped_sizes
= cropped_image
.size
58 self
.assertTrue((sizes
[0] - cropped_sizes
[0]) == 10)
60 def test_auto_crop1(self
):
62 fs
.unlink(root_path
+ file[1])
64 image
= PilImage
.open(root_path
+ file[0])
68 img
= MangaImage(root_path
+ file[0])
69 img
.crop_auto(root_path
+ file[1])
72 cropped_image
= PilImage
.open(root_path
+ file[1])
73 cropped_sizes
= cropped_image
.size
76 self
.assertTrue(sizes
[0] > cropped_sizes
[0])
78 def test_auto_crop2(self
):
80 fs
.unlink(root_path
+ file[1])
82 image
= PilImage
.open(root_path
+ file[0])
86 img
= MangaImage(root_path
+ file[0])
87 img
.crop_auto(root_path
+ file[1])
90 cropped_image
= PilImage
.open(root_path
+ file[1])
91 cropped_sizes
= cropped_image
.size
94 self
.assertTrue(sizes
[0] == cropped_sizes
[0])
96 def test_auto_crop3(self
):
98 fs
.unlink(root_path
+ file[1])
100 image
= PilImage
.open(root_path
+ file[0])
104 img
= MangaImage(root_path
+ file[0])
105 img
.crop_auto(root_path
+ file[1])
108 cropped_image
= PilImage
.open(root_path
+ file[1])
109 cropped_sizes
= cropped_image
.size
110 cropped_image
.close()
112 self
.assertTrue(sizes
[0] == (2 + cropped_sizes
[0])) # 2px black line
114 def test_image_not_found(self
):
115 self
.assertRaises(AttributeError, lambda: MangaImage(root_path
))
117 def test_gray1(self
):
118 file = files_paths
[1]
119 fs
.unlink(root_path
+ file[1])
121 image
= MangaImage(root_path
+ file[0])
122 image
.gray(root_path
+ file[1])
125 image
= PilImage
.open(root_path
+ file[1])
126 index
= image
.mode
.find('L')
129 self
.assertTrue(index
== 0)
131 def test_convert(self
):
132 file = files_paths
[0][0]
133 image
= MangaImage(root_path
+ file)
135 basename
= file[0:file.find('.')]
136 basename
= root_path
+ '/temp' + basename
+ '.bmp'
137 image
.convert(basename
)
140 self
.assertTrue(path
.isfile(basename
))