25
def show():

    file = raw_input("What is the name of the image file? ")

    picture = Image(file)

    width, height = picture.size()

    pix = picture.getPixels()

I am trying to write a code to display this image but this code does not provide the image. How to change my code in order to display this image?

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
hkus10
  • 463
  • 3
  • 7
  • 9

2 Answers2

56
from PIL import Image

image = Image.open('File.jpg')
image.show()
Moein Kameli
  • 976
  • 1
  • 12
  • 21
tiagoboldt
  • 2,426
  • 1
  • 24
  • 30
  • 4
    this just launches an external viewer application – endolith Jul 04 '17 at 01:02
  • 15
    This answer requires that you install [Pillow](https://pillow.readthedocs.io/en/3.1.x/installation.html#basic-installation) (or the original [PIL](https://bitbucket.org/effbot/pil-2009-raclette)) first. Note Pillow's syntax requires `from PIL import Image`. – Erik Koopmans May 06 '18 at 14:49
22

Don't forget to include

import Image

In order to show it use this :

Image.open('pathToFile').show()
White Shadow
  • 444
  • 2
  • 10
  • 26
dLobatog
  • 1,751
  • 16
  • 17