2013-06-29 58 views
7

我有一個縮略圖過濾器,當圖像高於廣角時,總是會將圖像向左旋轉90度(我檢查過了,原始圖像是直的,而高速緩存的圖像旋轉)。相關代碼如下所示:在Django-imagekit中停止圖像的自動旋轉縮略圖

profile_image = models.ImageField(upload_to='profile_images', default='profile_images/icon.png') 
profile_icon = ImageSpecField(source='profile_image', 
           processors=[processors.Thumbnail(width=72, height=72, crop=True)], 
           format='JPEG', 
           options={'quality': 60}) 

如何停止自動旋轉?

回答

2

好吧,事實證明,這是一個上傳圖像的問題,而不是Django的任何問題。在iPhone上拍攝的照片可能具有電話方向元數據,導致瀏覽器認爲照片的自然方向是橫向的。但是,如果我在預覽中打開該照片,向左旋轉然後恢復正常,然後再次保存,則不會出現問題。

Feed image shows rotated in certain browsers

驚喜!

7

很高興你知道這一點,但ImageKit可以幫你解決一些問題。檢查轉置處理器(imagekit.processors.Transpose)。默認情況下,它將使用圖像中的元數據,並按該數量旋轉!請確保首先列出此處理器,因爲後續處理器將從圖像中去除元數據。

+0

[imagekit文檔](https://django-imagekit.readthedocs.io/en/latest/) – brennan

3

爲了詳細說明matthewwithanm樂於助人的指針,OP的代碼將被調整,以便看起來像這樣:

profile_image = models.ImageField(upload_to='profile_images', default='profile_images/icon.png') 
profile_icon = ImageSpecField(source='profile_image', 
           processors=[ 
            processors.Transpose(), 
            processors.Thumbnail(width=72, height=72, crop=True) 
           ], 
           format='JPEG', 
           options={'quality': 60}) 

即,添加一個調用processors.Transpose()不帶任何參數。

我有從Flickr下載的原始肖像格式圖像的問題。該圖像(在iPhone上拍攝)爲縱向格式,默認情況下,imagekit在此情況下將其旋轉90度,逆時針旋轉。