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
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)
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_)
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
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
def _setData(self, data): super(NamedImage, self)._setData(data) contentType, self._width, self._height = getImageInfo(self._data) if contentType: self.contentType = contentType