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
  • 26,342
  • 6
  • 60
  • 70
hkus10
  • 443
  • 3
  • 7
  • 8

2 Answers2

55
from PIL import Image

image = Image.open('File.jpg')
image.show()
Moein Kameli
  • 887
  • 1
  • 10
  • 19
tiagoboldt
  • 2,426
  • 1
  • 23
  • 30
  • 4
    this just launches an external viewer application – endolith Jul 04 '17 at 01:02
  • 14
    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
  • 1
  • 9
  • 25
dLobatog
  • 3,474
  • 1
  • 21
  • 21