Пример #1
0
    def _run(self):
        if not self._jobs:
            return False
        
        job = self._jobs.pop(0)

        # FIXME: check if there is already a file and update is False

        if job.filename.lower().endswith('jpg'):
            try:
                epeg_thumbnail(job.filename, job.imagefile + '.jpg', job.size)
                job.imagefile += '.jpg'
                self._notify_client(job)
                return True
            except IOError:
                pass

        try:
            png_thumbnail(job.filename, job.imagefile + '.png', size)
            job.imagefile += '.png'
            self._notify_client(job)
            return True
        except:
            pass
        
        # maybe this is no image
        metadata = kaa.metadata.parse(job.filename)
        if metadata and metadata['media'] == 'video':
            # video file
            print 'video'
            job.metadata = metadata
            self.videothumb.append(job)
            return True

        if metadata and metadata['raw_image']:
            print 'FIXME: store raw data'
            self._create_failed_image(job)
            self._notify_client(job)
            return True
            
        # broken file
        self._create_failed_image(job)
        self._notify_client(job)
        return True
Пример #2
0
def create(src, size = NORMAL, destdir = DOT_THUMBNAIL, url = None):
    """
    Create a freedesktop.org thumbnail.
    """
    if not url:
        # create url to be placed in the thumbnail
        url = 'file://' + os.path.normpath(src)

    # create digest for filename
    hexdigest = md5.md5(url).hexdigest()

    if size == NORMAL:
        dest = destdir + '/normal/'
        size = (128, 128)
    else:
        dest = destdir + '/large/'
        size = (256, 256)
        
    if not os.path.isdir(dest):
        os.makedirs(dest, 0700)

    if src.lower().endswith('jpg'):
        try:
            _thumbnailer.epeg_thumbnail(src, dest + hexdigest + '.jpg', size)
            return dest + hexdigest + '.jpg'
        except IOError:
            pass
    try:
        _thumbnailer.png_thumbnail(src, dest + hexdigest + '.png', size)
        return dest + hexdigest + '.png'
    except:
        # image is broken
        dest = destdir + '/failed/kaa/'
        if not os.path.isdir(dest):
            os.makedirs(dest, 0700)
        _thumbnailer.fail_thumbnail(src, dest + hexdigest + '.png')
        return dest + hexdigest + '.png'