Question about photos.get_image
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
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>
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.
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>
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.
Then you'd want to save your photos as files first, as I've shown in the previous example.
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.
You will have to convert your image to RGBA. You can do it like this:
<PRE>img = Image.open('photo.jpeg').convert("RGBA")</PRE>
Success! Thanks for your patience.