Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THE ASSIGNMENT In this Milestone Project, we want you to show off your creativit

ID: 3602976 • Letter: T

Question

THE ASSIGNMENT

In this Milestone Project, we want you to show off your creativity and your Python image-manipulation skills. Please write a function named posterGenerator() that…

is correctly named posterGenerator()[5 points]

takes at least four inputs (function parameters), the Picture objects that you will combine onto the new canvas containing your poster [5 points]

modifies at least one of the input images using a whole-image manipulation (e.g., alter the color balance of the image, invert it, change it to grayscale, etc. — any of the manipulations shown in Chapter 4) [10 points]

modifies at least one of the input images using if and/or a selection area (e.g., remove red-eye in the image, posterize the image, replace a single color in the image, replace the background of the image, etc. — any of the manipulations shown in Chapter 5) [10 points]

creates a new canvas using makeEmptyPicture() to store your new output poster. Your poster should be roughly the proportions of a single sheet of paper (8-½” x 11”) [5 points]

copies all four of the input images (and/or their modified versions) onto the new canvas at appropriate locations [5 points each; 20 total]

adds at least five drawing primitives (e.g., text, rectangles, filled rectangles, ovals, etc.) to the poster — descriptions of your project, cause, or event; borders; grouping regions; and the like. NOTE: If you are looking to add larger text (such as a headline) to your image, you can either using an image that includes that text as one of your four+ input images and copy it to your canvas that way or you may look up the function addTextWithStyle() in the JES help to see how to change the font and size of the text that you manually draw on this image for these points [3 points each; 15 points total]

returns the new canvas containing your poster [5 points]

Also, at the bottom of your Python source file, please include:

A few lines of code that will:

ask the user to set the media path (e.g., setMediaPath());

load any image assets that your program needs using that media path;

call your generatePoster() function, passing in whatever images are needed to create the poster;

display the resulting image on the screen [5 points]

Explanation / Answer

Image processing and manipulation can be done in python by using many libraries . The most commonly used libraries for manipulation is Python Imaging Library (PIL) and OpenSource Computer Vision (OpenCV).

I will be using PIL library for image manipulation in my code .

Code :

1.For genearing canvas poster from image

from glob import iglob
from PIL import Image
import os

def posterGenarator(thumbpath, grid, thumb_size, background_color):

#Code for creating image to canvas poster .
page_num = 0
page_extent = grid[0]*thumb_size[0], grid[1]*thumb_size[1]

try:
while True:
paste_cnt = 0
#new_img = Image.new('RGB', page_extent, background_color)
for x in xrange(0, page_extent[0], thumb_size[0]):
for y in xrange(0, page_extent[1], thumb_size[1]):
try:
filepath = (yield)
except GeneratorExit:
print('GeneratorExit received')
return

filename = os.path.basename(filepath)
print('{} thumbnail -> ({}, {})'.format(filename, x, y))
#thumbnail_img = Image.open(filepath)
#thumbnail_img.thumbnail(thumb_size)
#new_img.paste(thumbnail_img, (x,y))
paste_cnt += 1
else:
continue # no break, continue outer loop
break # break occurred, terminate outer loop

print('====> thumbnail page completed')
if paste_cnt:
page_num += 1
print('Saving thumbpage{}.png'.format(page_num))
#img.save(
# os.path.join(thumbpath, 'thumbpage{}.png'.format(page_num)))
finally:
print('====> finally')
if paste_cnt:
page_num += 1
print('Saving thumbpage{}.png'.format(page_num))
#img.save(
# os.path.join(thumbpath, 'thumbpage{}.png'.format(page_num)))

path = '/media'
#npath = [infile for infile in iglob(os.path.join(path, '*.png'))]
npath = ['image{}.png'.format(i) for i in xrange(1, 37+1)] # test names

coroutine = thumbnailer(path, (3,6), (1000,1000), 'white')
coroutine.next() # start it

for filepath in npath:
coroutine.send(filepath)

print('====> closing coroutine')
coroutine.close()

2.Image manipulation

#Code for altering image manipulations by using below lines you can invert images.

3.Removing a red color from image

n = Image.open('test.jpg')
m = n.load()

# get x,y size
s = n.size

# iterate through x and y (every pixel)
for x in xrange(s[0]):
for y in xrange(s[1]):
r,g,b = m[x,y]
# remove red from the pic
m[x,y] = 0,g,b

# save the doctored image
n.save('sans_red.jpg', "JPEG")

4.Code for drawing rectangle,elipse,circle and line


image = Image.new('RGBA', (200, 200))
draw = ImageDraw.Draw(image)
draw.ellipse((20, 180, 180, 20), fill = 'blue', outline ='blue')
draw.point((100, 100), 'red')
image.save('ellipse.png')

im = Image.new('RGB', (100,200), (255,0,0))

dr = ImageDraw.Draw(im)

dr.ellipse((0,0,10,10), fill="black", outline = "blue")

im.save("circle.png")

im = Image.new('RGB', (100,200), (255,0,0))

dr = ImageDraw.Draw(im)

dr.rectangle(((0,0),(10,10)), fill="black", outline = "blue")

im.save("rectangle.png")