Skip to content
Related Articles

Related Articles

Wand – Create empty image with background
  • Last Updated : 22 Apr, 2020
GeeksforGeeks - Summer Carnival Banner

In Python we can create solid backgrounds using Wand. We can use these backgrounds for further use in image. We can use these backgrounds in a backgroundless image to make it more attractive. This can be done by simply using Image() function and setting width, height and background parameter.

Syntax :




with Image(width=<i>image_width </i>, 
           height=<i>image_height </i>, 
           background ='color') as img:
  
# other image manipulation code

Now Let’s see code to create backgrounds.

Example 1:




# import Image from wand.image module
from wand.image import Image
  
# create image using Image() function
with Image(width = 400, height = 300) as img:
  
    # Save image with a valid filename
    img.save(filename ='transparent.png')

Output :

 
Example 2: Crate a background with a solid green color






# import Color from wand.color module
from wand.color import Color
# import Image from wand.image module
from wand.image import Image
  
clr = Color('green')
with Image(width = 400, height = 300, background = clr) as img:
    img.save(filename ='green.png')

Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :