omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    FTP uploads compressed image

    Editorial
    2
    3
    1633
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • britishgaming
      britishgaming last edited by

      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

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        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).

        1 Reply Last reply Reply Quote 0
        • britishgaming
          britishgaming last edited by

          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...

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors