Exemplo n.º 1
0
def _encode_vcard_image(image, size=64):
    """Encode the image the vCard PHOTO format"""
    format = 'image/jpeg'
    image_data = create_thumbnail(image, size, size, format.split('/')[1])
    image_base64 = b64encode(image_data)
    properties = ('ENCODING=BASE64', 'TYPE=%s' % format)
    return image_base64, properties
Exemplo n.º 2
0
def _encode_vcard_image(image, size=64):
    """Encode the image the vCard PHOTO format"""
    format = 'image/jpeg'
    image_data = create_thumbnail(image, size, size, format.split('/')[1])
    image_base64 = b64encode(image_data)
    properties = ('ENCODING=BASE64', 'TYPE=%s' % format)
    return image_base64, properties
Exemplo n.º 3
0
def write_photo(uid, source):
    photo_date = datetime.now()  # we use a timestamp here to avoid browser/http server cache issues
    filename = photo_filename(uid, photo_date)
    path = os.path.join(_photo_path(), filename)

    # writes the profile photo
    tools.write_file(path,
                     tools.create_thumbnail(source, width=124, height=124))

    # writes the thumbnails
    for format, (width, height) in _ThumbnailsFormats.items():
        dir_path = _thumbnail_path(format)
        if not os.path.exists(dir_path):  # if the directory is missing, create it
            os.mkdir(dir_path)
        img_path = os.path.join(dir_path, filename)
        if not os.path.exists(img_path):
            tools.write_file(img_path,
                             tools.create_thumbnail(source, width=width, height=height))

    return photo_date
Exemplo n.º 4
0
    def _validate_thumbnail(self, f):
        if is_string(f):
            return None

        if f.done == -1:
            raise ValueError(_(u'Transfer was interrupted'))

        # finds out the filename (I.E. 4 returns the on-disk path)
        self.thumbnail_filename = f.filename.split('\\')[-1]

        try:
            return tools.create_thumbnail(f.file, 870, 271)
        except IOError as e:
            errno, strerror = e
            log.exception('thumbnail reception error: %s', strerror)
            raise IOError(errno, _(u'Reception error'))
Exemplo n.º 5
0
    def _validate_thumbnail(self, f):
        if is_string(f):
            return None

        if f.done == -1:
            raise ValueError(_(u'Transfer was interrupted'))

        # finds out the filename (I.E. 4 returns the on-disk path)
        self.thumbnail_filename = f.filename.split('\\')[-1]

        try:
            return tools.create_thumbnail(f.file, 870, 271)
        except IOError as e:
            errno, strerror = e
            log.exception('thumbnail reception error: %s', strerror)
            raise IOError(errno, _(u'Reception error'))