Forum Archive

FTP uploads compressed image

britishgaming

Hi guys

I'm having an issue with a workflow that uploads an image to an FTP server. Here's the code (adapted from a Pythonista example)

import webbrowser
import clipboard
import Image, ImageFile
import datetime
import photos
import ftplib
import urllib
from io import BytesIO

today = datetime.datetime.now()
image = photos.pick_image()
fileName = 'picture_iOS'
fileName = fileName + '_' + today.strftime("%Y-%m-%d-%H%M%S") + '.jpg'

urlBase = 'INSERT URL BASE'
encodedFileName = urllib.quote(fileName)

print fileName

buffer = BytesIO()
image.save(buffer, 'PNG')
buffer.seek(0)


ftp = ftplib.FTP('FTP URL', 'USERNAME', 'PASSWORD')
ftp.storbinary('STOR '+fileName, buffer)                        
ftp.quit()


clipboard.set(urlBase + encodedFileName)                                  

print 'Success! The link to your uploaded picture is now in your clipboard.'            

It works perfectly well, but the image it uploads is not the original image. Somewhere along the lines it has compressed it, and the result is not pretty.

If I upload the same image through Photogene's FTP export option it's perfect. So something must be going wrong in the workflow. Any ideas?

Thanks

omz

It seems a bit weird that your file name has a .jpg extension, but you appear to be saving a png. Not sure why this would lead to lossy compression though, as far as I can tell, the code should be saving a png file (though with an incorrect extension).

britishgaming

I've just been doing some extra testing

If I upload an image from a URL, it's fine. So the FTP code is perfect and isn't compressing anything.

I suppose it's the "photos.pick_image()" part. And I assume it's picking the compressed image (which iOS makes to speed up the Photos app) and not the original file.

Hmm...