Wand – Convert image format

Image Format describes how an image data is being stored. Different image formats have different merits and demerits. There are around 7 most common image formats which are used in different cases.
For example – The advantage of JPEG format is that it supports 24-bit color with up to 16 million colors. Thus, having high resolution. While PNG format have Low Resolution.

Image file formats :
1. JPEG(.jpeg)
2. PNG(.png)
3. TIFF(.tif or.tiff)
4. GIF(.gif)
5. Bitmap(.bmp)
6. EPS(.eps)

Note: To study in detail about Image Formats refer – Image Formats Article.

We can convert one image format to another using Wand library in Python using format property.

Syntax :



wand.image.format = 'final_format'

Code :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import Image from wand.image module
from wand.image import Image
  
# Read .png image using Image() function
with Image(filename ='koala.png') as img:
  
    # Change format in python using format property
    img.format = 'jpeg'
  
    # Save final image
    img.save(filename ='koala.jpg')

chevron_right


In output, we will get an image with name koala.jpeg with jpeg image format.

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

Hi there I am a student of CGC COE, Landran in CSE department and have a great interest in programming

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.