Class 34 — April 11
What do you picture – For your future life to be – We wish you success
Look both ways
- Image transformations
- When you paste a URL in reaction to a prompt, you must also type a space at the end of the line. Do not add a space at the beginning of the line.
- If your pasting URL has https://... rather than http://..., remove the s before hitting the enter key.
- Module manip.py
- Eventuall upports several common image transformations – duplicating, mirroring, flipping, rotating, scaling, and pixelation. Except for the pixelation transformation, all of the transformations copy values from the original image into the transformation.
- Tester test-manip.py
- See documentation for transform specifications.
manip.pysupports limited self-testing
- Questions to ask yourself before attempting the transformations:
- How do the dimensions of the transformation compare with the original?
- What is the correspondence between the pixels from the transformation with pixels from the original?
- Problem solving pattern
# get dimensions of the original
ow, oh = original.size
# set dimensions of the copy
nw, nh = ..., ...
# get a new appropriately sized image
new_image = Image.new( 'RGB', ( nw, nh ) )
# fill in every pixel of the new image
for nx in range( 0, nw ) : # consider every x value for the new image
for ny in range( 0, nh ) : # in tandem with every y value for the image
# set the spot to be filled in the new image
nspot = (nx ,ny )
# determine the corresponding spot in the original to be copied
ox = ...
oy = ...
ospot = ( ox, oy )
# get the pixel at the ospot
opixel = original.getpixel( ospot )
# determine the pixel for the new image
npixel = ...
# set the nspot in the new image
new_image.putpixel( nspot, npixel )
# return the filled in new image
- Read imaging epistle
scale with xfactor = 2.0 and yfactor = 2.0
scale with xfactor = 0.5 and yfactor = 0.5
scale with xfactor = 0.5 and yfactor = 2.0
scale with xfactor = 2.0 and yfactor = 0.5