Forum Archive

Handling images

deckarep

How do we get image assets into a Scene? For example the card game has references to image of each card type animal. If I was creating a game from scratch I do I load my image assets into my python script?

Also, is there a way to load an image dynamically from the web into a Scene? Similar to how I saw how the xmlrpclib python library could be dynamically downloaded and installed into Pythonista?

omz

There are basically two ways:
1. The editor has an insertion panel for built-in media resources (the [+] button at the top). You can add custom images from the clipboard there when you select "My Images" and then use them like the built-in ones.
2. Use PIL to load images from files (that may have been downloaded from the web using for example urllib or requests). You can then load those PIL images into a scene in the setup method using the load_pil_image function.

deckarep

Aha,

Okay, I got this working using method number 2. Follow up question if you wouldn't mind: Suppose I use requests/urlib to download an image, is it possible for the newly downloaded image to show up in the Images media selection page? Apparently whatever I downloaded will not show up there. It only shows up if I use the number 1 method (mentioned above) but it would be nice if the app somehow cataloged the dynamically downloaded images in the same spot.

Btw, omz, I'm blown away by this software. Python + iPad equals sweet, sweet love.

omz

No, that's not directly possible right now. The best you can do is to use my_image.show() to display your image in the console, then copy it to the clipboard by touching and holding it there, and add it to the media browser from the clipboard afterwards.

jpsilverberg230

Do you have any support or advice on rendering pdfs?

omz

No, sorry.

arronlee185

Hi, jpsilverberg. What do you mean by "support or advice on rendering pdfs"? You want a tool to help you deal with pdfs? I am also a green hand on this problem, have you got any suggestions?

Best regards,
Arron

ExParrot101

Hi—This is possibly the greatest app ever. I'm trying to use a png image (created elsewhere and placed in my Camera Roll) as a fixed asset. I don't find a [+] button in the editor title bar, per option 1.
In general, I'm not sure how to access the file system on my iPhone. (As a former dabbler iOS Developer, I expect each project to have a sandbox...?)
Thanks!

ccc

You need to click once in the text of the Editor pane to get the [+] to appear to the left of the [?].

ExParrot101

Could that [+] be iPad-specific? On my device (iPhone 5), the editor's title bar has only (L to R): Keyboard minimizer/library browse icon; Search (lens); Title (w/dropdown class & method picker); Help ('?'); Run/stop icon. (I want to use regions of my png as tile images for a game.)

ExParrot101

Also—Since I don't want to depend on the image to be in my Photos, the idea of a project sandbox or a persistent assets folder seems preferable. Or as a kludge, encoding the image as a string within a source file... Can you tell I'm new here?

omz

@Exparrot On the iPhone, that functionality is hidden in the menu, when you tap and hold the cursor, you should see an "Insert..." item there.

ExParrot101

Thanks! That got the image into the media browser with a name, right? I see an'_' prepended: _tileSet. What do I need to import to make that name visible? (Neither tileSet.show() nor _tileSet.show() works.)

ccc

@Exparrot To get something working with your image:

  • Create a new script (the '+' at the bottom of the list of scripts).
  • Select 'Scene with Layers' instead of selecting 'Empty' as the script template.
  • Edit line 12 to put your image file name (with underscore) in place of 'Snake'.
  • Run the script. Your image should be at the center of the screen. Click elsewhere to move your image.
  • To go full screen, edit line 10 to read: self.layer = Layer(self.bounds)
  • ExParrot101

    Thanks, ccc and omz! Traction at last. Voom!

    ccc

    The bare minimum script is:

    from PIL import Image; Image.open('_tileSet').show()