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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :