Saturday, November 16, 2024
Google search engine
HomeLanguagesPython – Image() function in Wand

Python – Image() function in Wand

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 :




# import required libraries
from __future__ import print_function
from wand.image import Image
  
    # read image using Image() function
    img = Image(filename ='koala.jpg')
  
    # print height of image
    print('height =', img.height)
  
    # print width of image
    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.




# import required libraries
from __future__ import print_function
from urllib2 import urlopen
from wand.image import Image
  
try:
         
        # read image using Image() function
        img = Image(file = response)
  
        # print height of image
        print('Height =', img.height)
  
        # print width of image
        print('Width =', img.width)
finally:
    response.close()


Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments