pgmagick is a GraphicsMagick binding for Python. This module provides methods for Image Editing and Manipulation. pgmagick is written by Hideo Hattori.
We can do a lot of things using this library such as :
Installation :
There are two ways to install pgmagick:
- Windows: Execute following command in Command Prompt-
pip install pgmagick
- Ubuntu : Execute the following command in Terminal-
### Ubuntu11.10+ ### $ apt-get install python-pgmagick ### Ubuntu10.04+ ### $ apt-get install libgraphicsmagick++1-dev $ apt-get install libboost-python1.40-dev
Example#1: Let’s discuss a code to resize the image-
For illustration purpose I have taken following sample image-
from pgmagick import Image #Include full path to the input image img = Image( 'input_image.jpg' ) img.filterType(FilterTypes.SincFilter) img.resize( '150x150' ) img.write( 'output_image.jpg' ) |
Output:
Example#2: Let’s discuss a code to scale the image-
I have used the same sample image for input as in above example.
from pgmagick import Image #Include full path to the input image img = Image( 'input_image.jpg' ) img.quality( 100 ) img.scale( '100x100' ) img.sharpen( 1.0 ) img.write( 'output_image.jpg' ) |
if you try running the code at your end, you will see that the image is successfully resampled as per the new dimensions and you will get a new image.
References:
- https://pypi.org/project/pgmagick/
- https://pythonhosted.org/pgmagick/#license
- https://pythonhosted.org/pgmagick/cookbook.html#
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.