如何使用EXIF的信息制作django

编程入门 行业动态 更新时间:2024-10-28 04:24:55
如何使用EXIF的信息制作django-photologue自动旋转图像?(How to make django-photologue autorotate image with info from EXIF?)

我需要在上传时根据EXIF中的信息更改图像的方向。 这有什么“标准”方式吗? 我现在试图修补模型,但不确定它的正确方法。

I need to change orientation of image according to info in EXIF on upload. Is there any "standard" way for this? Im trying to patch models now, but not sure its right way.

最满意答案

好吧,我做了这个文件photologue / models.py:

IMAGE_EXIF_ORIENTATION_MAP = { 6: 0, 3: 2, 8: 3, 1: 4, } def pre_cache(self): if self.EXIF.get('Orientation', 1) is not None: im = Image.open(self.image.path) im = im.transpose(IMAGE_EXIF_ORIENTATION_MAP[self.EXIF.get('Orientation', 1)]) im.save(self.image.path) cache = PhotoSizeCache() for photosize in cache.sizes.values(): if photosize.pre_cache: self.create_size(photosize)

Well, I did it like this file photologue/models.py:

IMAGE_EXIF_ORIENTATION_MAP = { 6: 0, 3: 2, 8: 3, 1: 4, } def pre_cache(self): if self.EXIF.get('Orientation', 1) is not None: im = Image.open(self.image.path) im = im.transpose(IMAGE_EXIF_ORIENTATION_MAP[self.EXIF.get('Orientation', 1)]) im.save(self.image.path) cache = PhotoSizeCache() for photosize in cache.sizes.values(): if photosize.pre_cache: self.create_size(photosize)

更多推荐

本文发布于:2023-07-21 07:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208076.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   信息   EXIF   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!