Пример #1
0
    def test_resize_gif(self):

        basename = os.path.basename(PREVIEW_GIF)
        size = (200, None)
        gallery.resize(PREVIEW_GIF, os.getcwd(), "", basename, size, 1)

        self.assertTrue(
            os.path.exists(utils.replace_extension(basename, ".gif")))
        output_size = gallery.get_size(basename, 1)
        self.assertEqual(output_size["width"], size[0])
Пример #2
0
    def test_resize_tiff(self):

        basename = os.path.basename(IMG_6218_TIFF)
        size = (1600, None)
        gallery.resize(IMG_6218_TIFF, os.getcwd(), "", basename, size, 1)

        expected_basename = utils.replace_extension(basename, ".tiff")
        self.assertTrue(os.path.exists(expected_basename))
        output_size = gallery.get_size(expected_basename, 1)
        self.assertEqual(output_size["width"], size[0])
Пример #3
0
    def test_resize_jpeg(self):

        basename = os.path.basename(IMG_3870_JPEG)
        size = (800, None)
        gallery.resize(IMG_3870_JPEG, os.getcwd(), "", basename, size, 1)

        self.assertTrue(
            os.path.exists(utils.replace_extension(basename, ".jpeg")))
        output_size = gallery.get_size(basename, 1)
        self.assertEqual(output_size["width"], size[0])
Пример #4
0
    def inner(path):
        root, dirname, basename = utils.tripple(from_directory, path)
        document = converters.frontmatter_document(
            root,
            os.path.join(dirname, basename),
            default_category=default_category)

        files = []

        # Thumbnail.
        try:
            if isinstance(document["thumbnail"],
                          str):  # work-around for legacy photo handling
                thumbnail_src = os.path.normpath(
                    os.path.join(from_directory, dirname,
                                 document["thumbnail"]))
                name, ext = os.path.splitext(basename)
                thumbnail_basename = "%s-thumbnail.jpg" % (name, )

                # Ensure the destination directory exists.
                # This is designed to fail if the destination path exists, but is not a directory.
                target_directory = os.path.join(to_directory, dirname)
                utils.makedirs(target_directory)

                document.metadata['thumbnail'] = gallery.resize(
                    thumbnail_src, to_directory, dirname, thumbnail_basename,
                    (None, 500), 2)
                files.append(
                    os.path.join(to_directory, dirname, thumbnail_basename))
        except KeyError:
            pass

        incontext.environment[DOCUMENT_STORE].add(document)
        return {'files': files, 'urls': [document.url]}