0% found this document useful (0 votes)
17 views8 pages

Apl Practical 1

Vishakha Sunil Patil wrote a program with PRN number 2041064 for the Advanced Programming Lab subject. The program performs various operations on images like retrieving the size, saving changes, rotating, cropping, and resizing an image. It uses the Python Imaging Library (PIL) module to open, manipulate, and save the images. The program outputs the results of running code snippets that implement each image operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Apl Practical 1

Vishakha Sunil Patil wrote a program with PRN number 2041064 for the Advanced Programming Lab subject. The program performs various operations on images like retrieving the size, saving changes, rotating, cropping, and resizing an image. It uses the Python Imaging Library (PIL) module to open, manipulate, and save the images. The program outputs the results of running code snippets that implement each image operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Name : Vishakha Sunil Patil

PRN Number : 2041064

Subject : Advanced Programming Lab

Aim : Write a program to perform following operations on images.

a. Retrieve size of an image


b. Save changes in an image
c. Rotating an image
d. Cropping an image
e. Resizing an image

Program :

#Retrieve size of an image


import PIL
from PIL import Image
img = PIL.Image.open("retrieve.jpg")
width, height = img.size
print(str(width) + " x " + str(height))
Output :
Program :

#Save changes in an image


from PIL import Image
img = ("resolution.jpg")
image = Image.open(img)
image.save("resolved_image.jpg", quality = 1)
Output :
Program :

#Rotating an image
from PIL import Image
img = Image.open("rotate.jpg")
rotated_image1 = img.rotate(180)
rotated_image2 = img.rotate(60)
rotated_image1.show()
rotated_image2.show()

Output :
Program :

#Cropping an image
from PIL import Image
img = Image.open("crop.jpg")
width, height = img.size
left = 5
top = height / 4
right = 164
bottom = 3 * height / 4
cropped_image = img.crop((left, top, right, bottom))
cropped_image.show()

Output :
Program :

#Resizing an image
from PIL import Image
img = Image.open("resize.jpg")
width, height = img.size
left = 4#
top = height / 5
right = 154
bottom = 3 * height / 5
resized_image = img.crop((left, right, bottom, top))
newsize = (300, 300)
resized_image = resized_image.resize(newsize)
resized_image.show()

Output :

You might also like