def _create_failed_image(self, job): dirname = os.path.dirname(os.path.dirname(job.imagefile)) + '/failed/kaa/' job.imagefile = dirname + os.path.basename(job.imagefile) + '.png' if not os.path.isdir(dirname): os.makedirs(dirname, 0700) fail_thumbnail(job.filename, job.imagefile) return
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'