मैं छवि को संपीड़ित करने और इसे उसी अभिविन्यास में रखने का एक तरीका खोजना चाहता हूं। मेरा कोड:
def save(self, **kwargs):
super(Post, self).save()
if self.picture:
mywidth = 1100
image = Image.open(self.picture)
wpercent = (mywidth / float(image.size[0]))
hsize = int((float(image.size[1]) * float(wpercent)))
image = image.resize((mywidth, hsize), Image.ANTIALIAS)
image.save(self.picture.path)
भले ही मैं बस इस बिट का उपयोग करता हूं:
image = Image.open(self.picture)
और फिर इसे बिना कुछ किए सेव करें
image.save(self.picture.path)
यह अभी भी मेरी तस्वीर को बदले हुए अभिविन्यास के साथ देता है ...
1 उत्तर
मुझे संदेह है कि आप उसी समस्या का सामना कर रहे हैं जैसे PIL थंबनेल मेरी छवि को घुमा रहा है?< /ए>
जनहित याचिका इस तरह छवि को घुमा नहीं रही है। छवि फ़ाइल में छवि के उन्मुखीकरण को ध्यान में रखते हुए एक ध्वज है, जिसे तकिया पढ़ रहा है, लेकिन आपकी नई फ़ाइल में सहेजा नहीं जा रहा है।
तो मैं कोशिश करूँगा -
from PIL import Image, ExifTags
def save(self, **kwargs):
super(Post, self).save()
if self.picture:
mywidth = 1100
image = Image.open(self.picture)
if hasattr(image, '_getexif'):
exif = image._getexif()
if exif:
for tag, label in ExifTags.TAGS.items():
if label == 'Orientation':
orientation = tag
break
if orientation in exif:
if exif[orientation] == 3:
image = image.rotate(180, expand=True)
elif exif[orientation] == 6:
image = image.rotate(270, expand=True)
elif exif[orientation] == 8:
image = image.rotate(90, expand=True)
wpercent = (mywidth / float(image.size[0]))
hsize = int((float(image.size[1]) * float(wpercent)))
image = image.resize((mywidth, hsize), Image.ANTIALIAS)
image.save(self.picture.path)
संबंधित सवाल
नए सवाल
python-3.x
पायथन प्रोग्रामिंग के बारे में प्रश्नों के लिए जो भाषा के संस्करण 3+ के लिए विशिष्ट हैं। सभी पायथन सवालों पर अधिक जेनेरिक [अजगर] टैग का उपयोग करें, और केवल यह जोड़ें यदि आपका प्रश्न संस्करण-विशिष्ट है। पायथन 2 प्रश्नों के लिए [अजगर -2] टैग का उपयोग करें।