示例#1
0
    def testWxThumbWidthTiff(self):
        self.fname_in = "testdata/images/outwiker_1.1.0_02.tiff"
        self.fname_out = "testdata/images/outwiker_1.1.0_02_th.png"

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)

        self.thumbmaker = ThumbmakerWx()
        newwidth = 250
        newheight = 215

        self.thumbmaker.thumbByWidth(self.fname_in, newwidth, self.fname_out)
        (width, height) = getImageSize(self.fname_out)

        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)
示例#2
0
    def testWxThumbHeightJpeg(self):
        self.fname_in = "testdata/images/first.jpg"
        self.fname_out = "testdata/images/first_th.jpg"

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)

        self.thumbmaker = ThumbmakerWx()
        newheight = 180
        newwidth = 246

        self.thumbmaker.thumbByHeight(self.fname_in, newheight, self.fname_out)
        (width, height) = getImageSize(self.fname_out)

        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)
示例#3
0
    def testAddIcons_19_resize(self):
        files = [
            '16x16.png', '16x15.png', '16x17.png', '15x16.png', '17x16.png',
            '17x17.png', '15x15.png', '8x8.png', '8x16.png', '16x8.png',
            'first.png', 'first_vertical.png'
        ]

        fullPaths = [os.path.join(self.imagesDir, fname) for fname in files]

        os.mkdir(self.tempDir1)
        collection = IconsCollection(self.tempDir1)
        collection.addIcons(None, fullPaths)

        icons = sorted(collection.getIcons(None))
        self.assertEqual(len(icons), 12)

        icons = {fname: os.path.join(self.tempDir1, fname) for fname in files}

        for fname in files:
            self.assertEqual(getImageSize(icons[fname]), (16, 16))
示例#4
0
    def testThumbByHeightJpeg(self):
        images_dir = "testdata/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 249
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByHeight(
            page, fname_in, newheight)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)
示例#5
0
    def testThumbByWidthPng(self):
        images_dir = "testdata/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByWidth(
            page, fname_in, newwidth)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)
示例#6
0
    def testWxThumbMaxSizeJpeg2(self):
        self.fname_in = "testdata/images/first_vertical.jpeg"
        self.fname_out = "testdata/images/first_vertical_th.jpg"

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)

        self.thumbmaker = ThumbmakerWx()
        newsize = 250

        newwidth = 182
        newheight = 250

        self.thumbmaker.thumbByMaxSize(self.fname_in, newsize, self.fname_out)
        (width, height) = getImageSize(self.fname_out)

        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)
示例#7
0
    def testThumbByMaxSizeJpeg2(self):
        images_dir = "testdata/images"

        fname_in = "first_vertical.jpeg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 182
        newheight = 250

        thumb_fname = self.thumbmaker.createThumbByMaxSize(
            page, fname_in, maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)
示例#8
0
    def testWxThumbMaxSize_08_png(self):
        self.fname_in = "testdata/images/8x16.png"
        self.fname_out = "testdata/images/_thumb.png"

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)

        self.thumbmaker = ThumbmakerPil()
        newsize = 16

        newwidth = 8
        newheight = 16

        self.thumbmaker.thumbByMaxSize(self.fname_in,
                                       newsize,
                                       self.fname_out,
                                       larger=False)
        (width, height) = getImageSize(self.fname_out)

        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

        if os.path.exists(self.fname_out):
            os.remove(self.fname_out)
示例#9
0
 def __getMaxImageSize(self, fname):
     (width, height) = getImageSize(fname)
     return max(width, height)