Esempio n. 1
0
# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]
# Copyright (c) 2015 Wikimedia Foundation

# XCF engine

from wikimedia_thumbor_base_engine import BaseWikimediaEngine


BaseWikimediaEngine.add_format(
    'image/xcf',
    '.xcf',
    lambda buffer: buffer.startswith('gimp xcf')
)


class Engine(BaseWikimediaEngine):
    def should_run(self, extension, buffer):
        return extension == '.xcf'

    def create_image(self, buffer):
        self.xcf_buffer = buffer
        self.prepare_temp_files(buffer)

        command = [
            self.context.config.XCF2PNG_PATH,
            self.source.name,
# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]
# Copyright (c) 2015 Wikimedia Foundation

# Ghostscript engine

from wikimedia_thumbor_base_engine import BaseWikimediaEngine


BaseWikimediaEngine.add_format(
    'application/pdf',
    '.pdf',
    lambda buffer: buffer.startswith('%PDF')
)


class Engine(BaseWikimediaEngine):
    def should_run(self, extension, buffer):
        return extension == '.pdf'

    def create_image(self, buffer):
        self.pdf_buffer = buffer
        self.prepare_temp_files(buffer)

        try:
            page = self.context.request.page
        except AttributeError:
Esempio n. 3
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]
# Copyright (c) 2015 Wikimedia Foundation

# XCF engine

from wikimedia_thumbor_base_engine import BaseWikimediaEngine

BaseWikimediaEngine.add_format('image/xcf', '.xcf',
                               lambda buffer: buffer.startswith('gimp xcf'))


class Engine(BaseWikimediaEngine):
    def should_run(self, extension, buffer):
        return extension == '.xcf'

    def create_image(self, buffer):
        self.xcf_buffer = buffer
        self.prepare_temp_files(buffer)

        command = [
            self.context.config.XCF2PNG_PATH, self.source.name, '-o',
            self.destination.name
        ]
Esempio n. 4
0
# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]
# Copyright (c) 2015 Wikimedia Foundation

# TIFF engine

from wikimedia_thumbor_base_engine import BaseWikimediaEngine


BaseWikimediaEngine.add_format(
    'image/tiff',
    '.tiff',
    lambda buffer: buffer.startswith('II*\x00') or buffer.startswith('MM\x00*')
)


class Engine(BaseWikimediaEngine):
    def should_run(self, extension, buffer):
        return extension == '.tiff'

    def create_image(self, buffer):
        self.tiff_buffer = buffer
        img = super(Engine, self).create_image(buffer)

        try:
            page = self.context.request.page
            img.seek(page - 1)
Esempio n. 5
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]
# Copyright (c) 2015 Wikimedia Foundation

# Ghostscript engine

from wikimedia_thumbor_base_engine import BaseWikimediaEngine

BaseWikimediaEngine.add_format('application/pdf', '.pdf',
                               lambda buffer: buffer.startswith('%PDF'))


class Engine(BaseWikimediaEngine):
    def should_run(self, extension, buffer):
        return extension == '.pdf'

    def create_image(self, buffer):
        self.pdf_buffer = buffer
        self.prepare_temp_files(buffer)

        try:
            page = self.context.request.page
        except AttributeError:
            page = 1
Esempio n. 6
0
# Copyright (c) 2015 Wikimedia Foundation

# VIPS engine

import errno
import os
import math
from tempfile import NamedTemporaryFile

from wikimedia_thumbor_base_engine import BaseWikimediaEngine


BaseWikimediaEngine.add_format(
    'image/tiff',
    '.tiff',
    lambda buffer: (
        buffer.startswith('II*\x00') or buffer.startswith('MM\x00*')
    )
)


class Engine(BaseWikimediaEngine):
    def should_run(self, extension, buffer):
        if extension not in ('.png', '.tiff'):
            return False

        self.context.vips = {}

        self.prepare_temp_files(buffer)

        command = [
Esempio n. 7
0
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com [email protected]
# Copyright (c) 2015 Wikimedia Foundation

# SVG engine

from io import BytesIO
import xml.etree.cElementTree as cElementTree

from wikimedia_thumbor_base_engine import BaseWikimediaEngine

BaseWikimediaEngine.add_format(
    'image/svg+xml',
    '.svg',
    lambda buffer: Engine.is_svg(buffer)
)


class Engine(BaseWikimediaEngine):
    @classmethod
    def is_svg(cls, buffer):
        try:
            for event, element in cElementTree.iterparse(
                BytesIO(buffer), ('start',)
            ):
                return element.tag == '{http://www.w3.org/2000/svg}svg'
        except cElementTree.ParseError:
            pass