Forum Archive

Displaying an image

freeradical321

Hey guys,

I'm completely new to pythonista, as well as python, and while we're at it, I'm completely new to programing in general! As such, I have what is probably a very simple question.

How do I display an image in pythonista on the ipad? I'm just trying to get my program to display one of the emojis included within the app, but I can't get it to work. Is there a package/module I need to load? What command should I be using? Help?

Thanks in advance

zencuke

There are a variety of ways to display images in different contexts. I suggest you look in the examples. Many use images in different ways. Besides the image demo examples several of the games are based on displaying and modifying images. Also try searching the doc for "image".

zencuke

BTW when you say "I couldn't get it to work" and ask for help you should post an example of what you tried. Otherwise the question is too vague to easily answer.

brumm
import console, os

# 'Smiling_1' can easily replaced by another image via  the + button
path = os.path.expanduser('~') + '/Pythonista.app/Textures/' + 'Smiling_1' + '.png'
console.show_image(path)
omz

A bit simpler:

import Image
img = Image.open('Smiling_1')
img.show()
ccc

You can also use path = os.path.expanduser('~/Pythonista.app/Textures/Smiling_1.png') to get the same path.

In Pythonista v1.6, no image is shown :-( not even with the new syntax: console.show_image('emj:Smiling_1').

omz

@ccc console.show_image only works with file paths, not built-in image names. I actually doubt that brumm's code would work even in Pythonista 1.5 (can't check right now) because the filesystem location of app bundles has changed in iOS 8 (the app bundle and the user documents are no longer in the same hierarchy).

brumm

@omz The code works fine with Pythonista 1.5 and iOS 8.3. Of course I haven't reinstalled Pythonista a long time (and not under iOS 8), so could it be that the old structure is valid? I hope I can update soon... ;)

ccc

I gotta say that I have learned to never second guess the code of Brumm... If he writes it then I believe. ;-)