thumbnail_PROCESSORS = ( 'easy_thumbnails.processors.colorspace','common.thumbnail_processors.pad_image','easy_thumbnails.processors.autocrop','easy_thumbnails.processors.scale_and_crop','easy_thumbnails.processors.filters')
然后你可以将它添加到common / thumbnail_processors.py(或任何地方)
import Imagedef pad_image(image,**kwargs): """ Pad an image to make it the same aspect ratio of the desired thumbnail. """ img_size = image.size des_size = kwargs['size'] fit = [float(img_size[i])/des_size[i] for i in range(0,2)] if fit[0] > fit[1]: new_image = image.resize((image.size[0],int(round(des_size[1]*fit[0])))) top = int((new_image.size[1] - image.size[1])/2) left = 0 elif fit[0] < fit[1]: new_image = image.resize((int(round(des_size[0]*fit[1])),image.size[1])) top = 0 left = int((new_image.size[0] - image.size[0])/2) else: return image # For transparent #mask=Image.new('L',new_image.size,color=0) #new_image.putAlpha(mask) # For white new_image.paste((255,255,255)) new_image.paste(image,(left,top)) return new_image总结
以上是内存溢出为你收集整理的django – 带有简单缩略图的衬垫全部内容,希望文章能够帮你解决django – 带有简单缩略图的衬垫所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)