Forum Archive

Image Rotation Issue with Pythonista 1.5

andeecollard

I'd just like to say Pythonista is an absolute life saver and I love using it. I've had an issue with Ole's email script that I've been using to upload dated image from gmail to flickr for an art project It worked fine prior to 1.5 but the portrait uploads now appear as landscape on flickr. I tried rotating the image in the code, but it had no effect. Any help gratefully received.

import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email import encoders
import Image
import photos
from io import BytesIO
import datetime
today = datetime.datetime.now()

def get_attachment(img):
    bytes = BytesIO()
    img.save(bytes, format='JPEG')
    msg = MIMEBase('image', 'jpeg')
    msg.set_payload(bytes.getvalue())
    encoders.encode_base64(msg)
    msg.add_header('Content-Disposition', 'attachment',
              filename='image.jpeg')
    return msg

def main():
    ### CHANGE THESE VALUES:
    to = '**********************@photos.flickr.com'
    subject = today.strftime("#%j")
    gmail_user = '*******************'
    gmail_pwd = '*******************'

    #Load a sample image, modify as needed:
    image = photos.pick_image(show_albums=False)
    print 'Connecting...'
    smtpserver = smtplib.SMTP("smtp.gmail.com", 587)

    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(gmail_user, gmail_pwd)

    print 'Preparing message...'
    outer = MIMEMultipart()
    outer['Subject'] = subject
    outer['To'] = to
    outer['From'] = gmail_user
    outer.preamble = 'You will not see this in a MIME-aware email reader.\n'
    attachment = get_attachment(image)
    outer.attach(attachment)
    composed = outer.as_string()

    print 'Sending...'
    smtpserver.sendmail(gmail_user, to, composed)
    smtpserver.close()
    print 'Done.'

if __name__ == '__main__':
    main()
ccc

Can you please edit your post above to put ` characters around the code so it does not get reformatted and is easier for us to understand? If you are going to include several lines of python code then put in a blank line followed by ```python {your code goes here} ``` and your code will be formatted as python.

omz

The behavior of the photos module has changed a bit in 1.5. By default, pick_image returns the original image data, which doesn't include adjustments like rotation, cropping or filters that you might have applied (or that were applied automatically) in the Photos app. If you want to get the image like it appears in the photos app, you can pass original=False as an additional parameter to the pick_image function.

andeecollard

Thank you Ole, worked first time. Fantastic work on both the recent updates.