Skip to content
Related Articles

Related Articles

Python – Scaling image using pgmagic
  • Last Updated : 08 May, 2020

Scaling is the process of resizing an image. We deal with the dimensions of an image. Scaling down deals with making image smaller while Scaling up refers to increase the size of image. Scaling is a very important process in image manipulation because sometimes we get image size smaller than expected and sometimes it is very large. So, in order to make image of perfect size to use Scaling is performed.

In this article we will learn how we can perform scaling using pgmagick in python.

Code :




# importing library
from pgmagick.api import Image
  
img = Image('gog.png')
  
# scaling image
img.scale((150, 100), 'lanczos')
img.write('scale_gog.png')

Input Image:

Output:

Scaling JPEG image –
JPEG Stands for Joint Photographic Experts Group. Due to high number color support upto 2^24 i.e. 16, 777, 216 this is used in commonly every digital camera. And support varying levels of compression.




# importing library
from pgmagick import Image, Blob
  
img = Image(Blob(open('koala.jpeg').read()))
  
# scaling image
img.scale('250x200')
img.write('scale_koala.jpeg')

Input Image:

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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :