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.
Handling images
-
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?
-
There are basically two ways:
- 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.
- Use <a href="http://omz-software.com/pythonista/docs/ios/PIL.html">PIL</a> to load images from files (that may have been downloaded from the web using for example <a href="http://omz-software.com/pythonista/docs/library/urllib">urllib</a> or <a href="http://omz-software.com/pythonista/docs/ios/requests">requests</a>). You can then load those PIL images into a scene in the setup method using the <a href="http://omz-software.com/pythonista/docs/ios/scene.html#scene.load_pil_image">load_pil_image</a> function.
-
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.
-
No, that's not directly possible right now. The best you can do is to use <code>my_image.show()</code> 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.
-
Do you have any support or advice on rendering pdfs?
-
No, sorry.
-
Hi, jpsilverberg. What do you mean by "support or advice on rendering pdfs"? You want a tool to help you deal with <a href="http://www.yiigo.com/net-document-image-plugin/pdf-plugin/">pdfs</a>? I am also a green hand on this problem, have you got any suggestions?
Best regards,
Arron -
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! -
You need to click once in the text of the Editor pane to get the [+] to appear to the left of the [?].
-
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.)
-
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?
-
@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.
-
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.)
-
@Exparrot To get something working with your image:
<li>Create a new script (the '+' at the bottom of the list of scripts).</li>
<li>Select 'Scene with Layers' instead of selecting 'Empty' as the script template.</li>
<li>Edit line 12 to put your image file name (with underscore) in place of 'Snake'.</li>
<li>Run the script. Your image should be at the center of the screen. Click elsewhere to move your image.</li>
<li>To go full screen, edit line 10 to read: self.layer = Layer(self.bounds)</li> -
Thanks, ccc and omz! Traction at last. Voom!
-
The bare minimum script is: <pre>from PIL import Image; Image.open('_tileSet').show()</pre>