In this specific article we will learn how to read our image through Python wand module. To read image in Wand we use Image() function. To manipulate an image first of all we need to read image in Python.
Parameters :
Parameter | Input Type | Description |
---|
image | Image | make exact copy of image |
blob | bytes | opens an image of blob byte array |
file | object | opens an image of the file object |
filename | basestring | opens image from filename |
width | numbers.Integral | the width of anew blank image or an image loaded from raw data |
height | numbers.Integral | the height of a new blank image or an image loaded from raw data |
depth | numbers.Integral | the depth used when loading raw data. |
background | wand.color.Color | an optional background color. |
colorspace | basestring | sets the stack’s default colorspace value before reading any images. |
units | basestring | paired with resolution for defining an image’s pixel density. |
Now we will write a code to print height and width of image.
Code :
from __future__ import print_function
from wand.image import Image
img = Image(filename = 'koala.jpg' )
print ( 'height =' , img.height)
print ( 'width = ' , img.width)
|
Output :
height = 300
width = 400
We can also read image from a url using urlopen
function from urllib2 generic python library. Let’s see code to print image height and width read from a url.
from __future__ import print_function
from urllib2 import urlopen
from wand.image import Image
try :
img = Image( file = response)
print ( 'Height =' , img.height)
print ( 'Width =' , img.width)
finally :
response.close()
|