def load_sync(context, url, callback): # Disable storage of original. These lines are useful if # you want your Thumbor instance to store all originals persistently # except video frames. # # from thumbor.storages.no_storage import Storage as NoStorage # context.modules.storage = NoStorage(context) unquoted_url = unquote(url) command = BaseWikimediaEngine.wrap_command([ context.config.FFPROBE_PATH, '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', '%s%s' % (uri_scheme, unquoted_url) ], context) logger.debug('Command: %r' % command) process = Subprocess(command, stdout=Subprocess.STREAM) process.set_exit_callback( partial( _parse_time_status, context, unquoted_url, callback, process ) )
def _parse_time(context, url, callback, output): duration = float(output) unquoted_url = unquote(url) try: seek = int(context.request.page) except AttributeError: seek = duration / 2 destination = NamedTemporaryFile(delete=False) command = BaseWikimediaEngine.wrap_command([ context.config.FFMPEG_PATH, # Order is important, for fast seeking -ss has to come before -i # As explained on https://trac.ffmpeg.org/wiki/Seeking '-ss', '%d' % seek, '-i', '%s%s' % (uri_scheme, unquoted_url), '-y', '-vframes', '1', '-an', '-f', 'image2', '-nostats', '-loglevel', 'error', destination.name ], context) logger.debug('Command: %r' % command) process = Subprocess(command) process.set_exit_callback( partial( _process_output, callback, destination.name ) )
def load_sync(context, url, callback): # Disable storage of original. These lines are useful if # you want your Thumbor instance to store all originals persistently # except video frames. # # from thumbor.storages.no_storage import Storage as NoStorage # context.modules.storage = NoStorage(context) unquoted_url = unquote(url) command = BaseWikimediaEngine.wrap_command([ context.config.FFPROBE_PATH, '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', '%s%s' % (uri_scheme, unquoted_url) ], context) logger.debug('Command: %r' % command) process = Subprocess(command, stdout=Subprocess.STREAM) process.set_exit_callback( partial(_parse_time_status, context, unquoted_url, callback, process))
def _parse_time(context, url, callback, output): duration = float(output) unquoted_url = unquote(url) try: seek = int(context.request.page) except AttributeError: seek = duration / 2 destination = NamedTemporaryFile(delete=False) command = BaseWikimediaEngine.wrap_command( [ context.config.FFMPEG_PATH, # Order is important, for fast seeking -ss has to come before -i # As explained on https://trac.ffmpeg.org/wiki/Seeking '-ss', '%d' % seek, '-i', '%s%s' % (uri_scheme, unquoted_url), '-y', '-vframes', '1', '-an', '-f', 'image2', '-nostats', '-loglevel', 'error', destination.name ], context) logger.debug('Command: %r' % command) process = Subprocess(command) process.set_exit_callback( partial(_process_output, callback, destination.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:
# 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,
#!/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 ]
# 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)
#!/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
# 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 = [
# 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