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.


    How to save image via photos.save_image()?

    Pythonista
    5
    7
    7350
    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.
    • jugisto135
      jugisto135 last edited by

      I've tried passing along a URL to an image, which didn't work. I kind if expected that, but do i have to create a temporary image file locally to pass it along? Do I have to use PIL?

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

        You have to use PIL to load or create an image first, then you can pass that image object to the save_image function in the photos module.

        You cannot open an image URL directly with PIL, but it doesn't require a lot of code to download an image into a memory buffer that can then be passed to PIL. Here's an example:

        import Image
        import photos
        from urllib import urlopen
        from io import BytesIO
        
        print "Downloading image..."
        url = "http://omz-software.com/pythonista/docs/_static/pythonista_icon.png"
        img = Image.open(BytesIO(urlopen(url).read()))
        photos.save_image(img)
        print "Image saved to camera roll."
        
        1 Reply Last reply Reply Quote 1
        • jugisto135
          jugisto135 last edited by

          Great, thanks.

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

            hi there, quick searching on Google brings me here.and Im working on image saving ,Is the codes above written in .Net? If yes ,Plz give me more detail guide,thx in adv.as a beginner in image programming ,I just can't figure out which open source code is best suiting me, like<a href="http://www.rasteredge.com/how-to/csharp-imaging/imaging-saving-printing/"> image save </a> sample codes found by Google as well as your codes.Any suggestion is appreciated.

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

              @nesca This has absolutely nothing to do with .NET. For information about how to save images in .NET, you might want to search stackoverflow.com (be sure to include .NET in your search), but I'm afraid, we can't really help you here.

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

                When saving a photo from an image URL, does it have to be a PNG?

                I've been testing it with a few urls and I keep getting 'IOError: cannot identify image file' for JPGs. Works fine for PNGs.

                Thanks!

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

                  Should be fine with .jpg

                  e.g. (if the URL is in the clipboard)

                  from photos import save_image
                  from Image import open as open_image
                  from cStringIO import StringIO as string_as_file
                  from urllib import urlopen
                  from clipboard import get as get_clip
                  
                  save_image(
                      open_image(
                          string_as_file(
                              urlopen(
                                  get_clip()
                              ).read()
                          )
                      )
                  )
                   
                  print 'Saved'
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors