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 :
Python3 1==
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.
Python3 1==
- Resize, rotate, sharpen, color reduce, or add special effects to an image.
- Create transparent image assets.
- Compare two images.
- Create a gradient image.
- Draw Text.
- Draw Text of 2 byte code.
- Get image size
- Edge extraction
- Create GIF animation using images.
- Add frames to image.
- Converts images from one format to another.
- 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
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')
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