使用PIL自动旋转手机拍摄的照片和光度计 [英] Using PIL to auto rotate picture taken with cell phone and accelorometer

查看:245
本文介绍了使用PIL自动旋转手机拍摄的照片和光度计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络应用程序中使用Django + PIL + Amazon boto。用户发送图片并且webapp显示它。大多数情况下,人们从他们的手机发送照片。有时,图像显示方向错误。有没有办法使用PIL或Django的ImageField从图像中获取元信息,并使用它将图像旋转到正确的方向?

解决方案

我正在使用 django-imagekit 处理图像,然后使用 imagekit.processors.Transpose

  from imagekit.models import ImageSpecField 
from imagekit.processors import ResizeToFill,Transpose,SmartResize

class UserProfile(models.Model):
avatar = models.ImageField(upload_to ='upload / avatars',max_length =空白= True,null = True)
avatar_thumbnail = ImageSpecField(
source ='avatar',
processors = [Transpose(),SmartResize(200,200)],
格式='JPEG',
options = {'quality':75}


I am using Django + PIL + Amazon boto in a web app. The user sends in the picture and the webapp displays it. Mostly, people send in photo taken from their cell phone. Sometimes, the image is displayed in the wrong orientation. Is there a way to use PIL or Django's ImageField to get the meta information from the image and to use it to rotate the image to the correct orientation?

解决方案

I'm using django-imagekit for processing images then using imagekit.processors.Transpose

from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill, Transpose, SmartResize

class UserProfile(models.Model):
  avatar = models.ImageField(upload_to='upload/avatars', max_length=255, blank=True, null=True)
  avatar_thumbnail = ImageSpecField(
    source='avatar',
    processors = [Transpose(),SmartResize(200, 200)],
    format = 'JPEG',
    options = {'quality': 75}
  )

这篇关于使用PIL自动旋转手机拍摄的照片和光度计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆