Example #1
0
def install_Image(lis):
    # `import Image` only works if the file `PIL.pth` exists in
    # site-packages. This is not always the case.
    try:
        from PIL import Image
    except:
        # just a backup
        import Image
    # PIL uses lazy initialization.
    # you candecide if you want only the
    # default stuff:
    Image.preinit()
    # or just everything:
    Image.init()
    import sys
    for name in sys.modules:
        if name[-11:] == "ImagePlugin":
            lis.append(name)
Example #2
0
    def _init_pillow(self):
        with self._lock:
            if not self._pillow_imported:
                self._pillow_imported = True  # more like tried to import
                import PIL
                if not hasattr(PIL, 'PILLOW_VERSION'):
                    raise ImportError('Imageio Pillow requires '
                                      'Pillow, not PIL!')
                from PIL import Image
                self._Image = Image
            elif self._Image is None:
                raise RuntimeError('Imageio Pillow plugin requires '
                                   'Pillow lib.')
            Image = self._Image

        if self.plugin_id in ('PNG', 'JPEG', 'BMP', 'GIF', 'PPM'):
            Image.preinit()
        else:
            Image.init()
        return Image
Example #3
0
    def _init_pillow(self):
        with self._lock:
            if not self._pillow_imported:
                self._pillow_imported = True  # more like tried to import
                import PIL

                if not hasattr(PIL, "__version__"):  # pragma: no cover
                    raise ImportError(
                        "Imageio Pillow plugin requires " "Pillow, not PIL!"
                    )
                from PIL import Image

                self._Image = Image
            elif self._Image is None:  # pragma: no cover
                raise RuntimeError("Imageio Pillow plugin requires " "Pillow lib.")
            Image = self._Image

        if self.plugin_id in ("PNG", "JPEG", "BMP", "GIF", "PPM"):
            Image.preinit()
        else:
            Image.init()
        return Image
Example #4
0
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

try:
    import cStringIO as StringIO
except ImportError:
    import StringIO

from PIL import Image
from PIL import ImageEnhance
from random import randrange

# Preload PIL with the minimal subset of image formats we need
Image.preinit()
Image._initialized = 2

# ----------------------------------------
# Image resizing
# ----------------------------------------

def image_resize_image(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=False):
    """ Function to resize an image. The image will be resized to the given
        size, while keeping the aspect ratios, and holes in the image will be
        filled with transparent background. The image will not be stretched if
        smaller than the expected size.
        Steps of the resizing:
        - Compute width and height if not specified.
        - if avoid_if_small: if both image sizes are smaller than the requested
          sizes, the original image is returned. This is used to avoid adding
          transparent content around images that we do not want to alter but
          just resize if too big. This is used for example when storing images
Example #5
0
    'kp5': rfb.KEY_KP_5,
    'kp6': rfb.KEY_KP_6,
    'kp7': rfb.KEY_KP_7,
    'kp8': rfb.KEY_KP_8,
    'kp9': rfb.KEY_KP_9,
    'kpenter': rfb.KEY_KP_Enter,
}

# Enable using vncdotool without PIL. Of course capture and expect
# won't work but at least we can still offer key, type, press and
# move.
try:
    from PIL import Image
    # Init PIL to make sure it will not try to import plugin libraries
    # in a thread.
    Image.preinit()
    Image.init()
except ImportError as error:
    # If there is no PIL, raise ImportError where someone tries to use
    # it.
    class _Image(object):
        def __getattr__(self, _):
            raise ImportError(error)

    Image = _Image()


class AuthenticationError(Exception):
    """ VNC Server requires Authentication """

Example #6
0
# -*- coding: utf-8 -*-
# Create by: Yefe @ 2009-8-19
# $Id$
from django import forms
from website.apps.account.models import User
from PIL import Image; Image.preinit()

IMAGE_SUPPORT_FORMAT = ', '.join(Image.OPEN.keys())


class ProfileForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('gender','birthday')

class FunctionForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('book_auto_save_point',)


class AvatarForm(forms.Form):
    avatar = forms.ImageField(label=u"上传头像图片", help_text=u"支持的图像文件格式: %s" % (IMAGE_SUPPORT_FORMAT))

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super(AvatarForm, self).__init__(*args, **kwargs)

    def save(self):
        f = self.cleaned_data["avatar"]
        if f is not None: