Skip to content
Related Articles

Related Articles

pgmagick Python- Introduction and Installation

View Discussion
Improve Article
Save Article
  • Last Updated : 11 May, 2020

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 :

  1. Resize, rotate, sharpen, color reduce, or add special effects to an image.
  2. Create transparent image assets.
  3. Compare two images.
  4. Create a gradient image.
  5. Draw Text.
  6. Draw Text of 2 byte code.
  7. Get image size
  8. Edge extraction
  9. Create GIF animation using images.
  10. Add frames to image.
  11. Converts images from one format to another.

Installation :
There are two ways to install pgmagick:

  1. Windows: Execute following command in Command Prompt-
    pip install pgmagick
    
  2. 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:

  1. https://pypi.org/project/pgmagick/
  2. https://pythonhosted.org/pgmagick/#license
  3. https://pythonhosted.org/pgmagick/cookbook.html#
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!