Esempio n. 1
0
def register_font(font='Vera.ttf'):
    """Register fonts for report labs canvas."""
    directory = os.path.join(bundle_dir())
    ttfFile = resource_path(os.path.join(directory, font))
    if os.path.exists(ttfFile):
        pdfmetrics.registerFont(TTFont("Vera", ttfFile))
        return ttfFile
    else:
        print(ttfFile, 'can not be found')
    def save(self, img=None, destination=None, file_name='pil', ext='.png'):
        img = self.img if not img else img
        if destination:
            output = os.path.join(destination, Path(file_name).stem + ext)
        elif self.tempdir:
            tmpimg = NamedTemporaryFile(suffix='.png',
                                        dir=self.tempdir.name,
                                        delete=False)
            output = resource_path(tmpimg.name)
            tmpimg.close()
        else:
            output = os.path.join(bundle_dir(), file_name + ext)

        # Save image file
        img.save(output)
        return output
Esempio n. 3
0
    def save(self, img=None, destination=None, file_name='pil'):
        img = self.img if not img else img
        fn = file_name.replace('.png',
                               '') if file_name.endswith('.png') else file_name
        if destination:
            output = os.path.join(destination, fn + '.png')
        elif self.tempdir:
            tmpimg = NamedTemporaryFile(suffix='.png',
                                        dir=self.tempdir.name,
                                        delete=False)
            output = resource_path(tmpimg.name)
            tmpimg.close()
        else:
            output = os.path.join(bundle_dir(), fn + '.png')

        # Save image file
        img.save(output)
        return output
Esempio n. 4
0
def _image_directory():
    directory = os.path.join(bundle_dir(), 'img')
    if os.path.exists(directory):
        return directory
    else:
        print(directory, 'can not be found')
Esempio n. 5
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
from PyBundle import bundle_dir

GRAY_PATH = os.path.join(bundle_dir(), 'Gray-CIE_L.icc')

try:
    from PIL import ImageCms
    gray = ImageCms.ImageCmsProfile(GRAY_PATH)
    sRGB = ImageCms.createProfile('sRGB')
except ImportError:
    gray = None
    sRGB = None