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.


    Question about photos.get_image

    Pythonista
    3
    9
    5438
    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.
    • jimwims
      jimwims last edited by

      I have a script which uses photos.get_image multiple times with the index numbers hard coded into the script. A problem is that when lower numbered photos are subsequently deleted from the camera roll, the index numbers for the photos I want are changed so I have to change the script. Is there a way around this?

      Tnx, Jim

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

        Not really, if you always want the same images from the camera roll, it might make sense to save them as files into the documents folder. Here's an example of how to save a photo as a jpeg file:

        <pre>import photos
        img = photos.get_image(0)
        with open('photo.jpeg', 'w') as f:
        img.save(f, 'jpeg')</pre>
        ...and this is how you would load it again:

        <pre>import Image
        img = Image.open('photo.jpeg')</pre>

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

          Once the photo is loaded using the statement in the second block above in the draw function of a Scene script, can 'img' be used in an image drawing function to display the photo? I am using a statement of the form

          image('img', x, y, w, h)

          immediately after your Image.open statement. I am getting only a white box where the photo should be.

          Thanks.

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

            No, when you want to load a PIL image into a scene, you have to use the <code>load_pil_image</code> function. It will return a string that can be used as the image name. That string is basically random (but unique) and not the same as the variable name. Basic example:

            <pre>from scene import *
            import photos
            class PhotoScene (Scene):
            def setup(self):
            img = photos.get_image(0)
            self.img = load_pil_image(img)
            def draw(self):
            image(self.img, 0, 0, self.size.w, self.size.h)
            </pre>

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

              Thanks for this, but I'm not sure I understand. My goal is to avoid using photos.get_Image() and its use of the camera roll index number.

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

                Then you'd want to save your photos as files first, as I've shown in the previous example.

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

                  Yes. I did that. But I can't display them using image(). I tried using load_pll_image to load the saved photo followed by image(...) to display it, but get an error message that only RGBA is supported by load_pll_ image. Tnx.

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

                    You will have to convert your image to RGBA. You can do it like this:
                    <PRE>img = Image.open('photo.jpeg').convert("RGBA")</PRE>

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

                      Success! Thanks for your patience.

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