コード例 #1
0
ファイル: jpg.py プロジェクト: Zojax/zojax.converter
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
""" JPEG -> JPEG

$Id$
"""
from zojax.converter.utils import log
from zojax.converter.image.pilimage import PILImageConverter

import PIL.Image

# check encoders
try:
    PIL.Image.core.jpeg_decoder
    PIL.Image.core.jpeg_encoder
except:
    log("JPEG converters are not available. PIL doesn't support this formats")
    raise ImportError()


class JPEGtoJPEGConverter(PILImageConverter):

    _from_format = 'jpeg'
    _dest_format = 'jpeg'
コード例 #2
0
ファイル: pilimage.py プロジェクト: Zojax/zojax.converter
##############################################################################
""" PIL based image converter

$Id$
"""
from cStringIO import StringIO

from zope import interface
from zojax.converter.utils import log
from zojax.converter.interfaces import ConverterException
from zojax.converter.interfaces import ISimpleImageConverter

try:
    import PIL.Image
except:
    log("Python Imaging library is not available.")
    raise ImportError()


class PILImageConverter(object):
    interface.implementsOnly(ISimpleImageConverter)

    _from_format = 'raw'
    _dest_format = 'raw'

    def convert(self, data, width=None, height=None, scale=0, quality=88):
        """ convert image """
        data.seek(0, 0)
        try:
            image = PIL.Image.open(data)
コード例 #3
0
ファイル: pnggif.py プロジェクト: Zojax/zojax.converter
""" GIF -> PNG and PNG - > GIF converters

$Id$
"""
from zojax.converter.utils import log
from zojax.converter.image.pilimage import PILImageConverter

import PIL.Image

# check encoders
try:
    PIL.Image.core.gif_decoder
    PIL.Image.core.gif_encoder
    PIL.Image.core.zip_decoder
    PIL.Image.core.zip_encoder
except:
    log("PNG/GIF converters are not available. PIL doesn't support this formats")
    raise ImportError()


class PNGtoGIFConverter(PILImageConverter):

    _from_format = 'zip'
    _dest_format = 'gif'


class GIFtoPNGConverter(PILImageConverter):

    _from_format = 'gif'
    _dest_format = 'zip'