Skip to content
Advertisement

Using pythons open function for .png Image

Im getting an error when using pythons inbuild function “open” and don’t know how to get it to work for png files.

Examplecode: img =open('here.png').read()

Error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 101: character maps to <undefined>

Advertisement

Answer

To open images, i suggest you to use opencv or PIL module of python.
Using OpenCV:

import cv2
img = cv2.imread('here.png',0)

Using PIL:

from PIL import Image
im = Image.open("here.png")
im.show()

If you just want to open using open :

img =open('here.png','rb').read()
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement