Beispiel #1
0
 def _setData(self, data):
     super(NamedBlobImage, self)._setData(data)
     firstbytes = self.getFirstBytes()
     res = getImageInfo(firstbytes)
     if res == ('image/jpeg', -1, -1) or res == ('image/tiff', -1, -1):
         # header was longer than firstbytes
         start = len(firstbytes)
         length = max(0, MAX_INFO_BYTES - start)
         firstbytes += self.getFirstBytes(start, length)
         res = getImageInfo(firstbytes)
     contentType, self._width, self._height = res
     if contentType:
         self.contentType = contentType
Beispiel #2
0
 def _setData(self, data):
     super(NamedBlobImage, self)._setData(data)
     firstbytes = self.getFirstBytes()
     res = getImageInfo(firstbytes)
     if res == ('image/jpeg', -1, -1) or res == ('image/tiff', -1, -1):
         # header was longer than firstbytes
         start = len(firstbytes)
         length = max(0, MAX_INFO_BYTES - start)
         firstbytes += self.getFirstBytes(start, length)
         res = getImageInfo(firstbytes)
     contentType, self._width, self._height = res
     if contentType:
         self.contentType = contentType
Beispiel #3
0
    def getImageSize(self):
        """See interface `IImage`"""
        if (self._width, self._height) != (-1, -1):
            return (self._width, self._height)

        contentType, self._width, self._height = getImageInfo(self.data)
        return (self._width, self._height)
Beispiel #4
0
    def getImageSize(self):
        """See interface `IImage`"""
        if (self._width, self._height) != (-1, -1):
            return (self._width, self._height)

        contentType, self._width, self._height = getImageInfo(self.data)
        return (self._width, self._height)
Beispiel #5
0
    def create(self, file_):
        content_type, width, height = getImageInfo(file_.read())
        file_.seek(0)
        if not content_type:
            error = translate(_('Only images can be added to the gallery.'), context=self.request)
            raise BadRequest(error)

        return self.create_obj('Image', 'image', file_)
Beispiel #6
0
    def __init__(self, data=b'', contentType='', filename=None):
        self.contentType, self._width, self._height = getImageInfo(data)
        self.filename = filename
        self._setData(data)

        # Allow override of the image sniffer
        if contentType:
            self.contentType = contentType

        exif_data = get_exif(data)
        if exif_data is not None:
            log.debug('Image contains Exif Informations. '
                      'Test for Image Orientation and Rotate if necessary.'
                      'Exif Data: %s', exif_data)
            orientation = exif_data['0th'].get(piexif.ImageIFD.Orientation, 1)
            if 1 < orientation <= 8:
                self.data, self._width, self._height, self.exif = rotate_image(
                    self.data)
            self.exif_data = exif_data
Beispiel #7
0
    def __init__(self, data='', contentType='', filename=None):
        self.contentType, self._width, self._height = getImageInfo(data)
        self.filename = filename
        self._setData(data)

        # Allow override of the image sniffer
        if contentType:
            self.contentType = contentType

        exif_data = get_exif(data)
        if exif_data is not None:
            log.debug('Image contains Exif Informations. '
                      'Test for Image Orientation and Rotate if necessary.'
                      'Exif Data: %s', exif_data)
            orientation = exif_data['0th'].get(piexif.ImageIFD.Orientation, 1)
            if 1 < orientation <= 8:
                self.data, self._width, self._height, self.exif = rotate_image(
                    self.data)
            self.exif_data = exif_data
Beispiel #8
0
    def _setData(self, data):
        super(NamedImage, self)._setData(data)

        contentType, self._width, self._height = getImageInfo(self._data)
        if contentType:
            self.contentType = contentType
Beispiel #9
0
    def _setData(self, data):
        super(NamedImage, self)._setData(data)

        contentType, self._width, self._height = getImageInfo(self._data)
        if contentType:
            self.contentType = contentType