def reduceImage(): # select picture to reduce file = pickAFile() opict = makePicture (file) # get the width, heigh owid = getWidth (opict) ohgt = getHeight(opict) # determine width and height of reduced image rwid = owid/2 rhgt = ohgt/2 # create an empty image with the "reduced" dimensions rpict = makeEmptyPicture(rwid, rhgt) # loop for the x and y positions from the original image for ox in range(1,owid,2): for oy in range(1,ohgt,2): # get pixel from original picture opixel = getPixel (opict, ox, oy) # get pixel from reduced picture rx = (ox+1)/2 ry = (oy+1)/2 rpixel = getPixel (rpict, rx, ry) # copy color from original pixel to reduced pixel c = getColor (opixel) setColor (rpixel, c) show (opict) show (rpict) def reduceImage2(): # select picture to reduce file = pickAFile() opict = makePicture (file) # get the width, heigh owid = getWidth (opict) ohgt = getHeight(opict) # determine width and height of reduced image rwid = owid/2 rhgt = ohgt/2 # create an empty image with the "reduced" dimensions rpict = makeEmptyPicture(rwid, rhgt) # loop for the x and y positions from the original image for ox in range(1,owid,2): for oy in range(1,ohgt,2): # get pixel from original picture opixel1 = getPixel (opict, ox, oy) opixel2 = getPixel (opict, ox+1, oy) opixel3 = getPixel (opict, ox, oy+1) opixel4 = getPixel (opict, ox+1, oy+1) # get pixel from reduced picture rx = (ox+1)/2 ry = (oy+1)/2 rpixel = getPixel (rpict, rx, ry) # copy color from original pixel to reduced pixel redTotal = getRed (opixel1) + getRed(opixel2) + getRed(opixel3) + getRed (opixel4) setRed (rpixel, redTotal/4) greenTotal = getGreen (opixel1) + getGreen(opixel2) + getGreen(opixel3) + getGreen (opixel4) setGreen (rpixel, greenTotal/4) blueTotal = getBlue (opixel1) + getBlue(opixel2) + getBlue(opixel3) + getBlue (opixel4) setBlue (rpixel, blueTotal/4) show (opict) show (rpict) def enlargeImage(): # select picture to enlarge file = pickAFile() opict = makePicture (file) # get the width, heigh owid = getWidth (opict) ohgt = getHeight(opict) # determine width and height of reduced image nwid = 2 * owid nhgt = 2 * ohgt # create an empty image with the "reduced" dimensions npict = makeEmptyPicture(nwid, nhgt) # loop for the x and y positions from the original image for ox in range(1,owid,): for oy in range(1,ohgt,): # get pixel from original picture opixel = getPixel (opict, ox, oy) # get pixel from reduced picture nx = (2 * ox) - 1 ny = (2 * oy) - 1 npixel1 = getPixel (npict, nx, ny) npixel2 = getPixel (npict, nx+1, ny) npixel3 = getPixel (npict, nx, ny+1) npixel4 = getPixel (npict, nx+1, ny+1) # copy color from original pixel to reduced pixel c = getColor (opixel) setColor (npixel1, c) setColor (npixel2, c) setColor (npixel3, c) setColor (npixel4, c) show (opict) show (npict) def addLines(): file = pickAFile() source = makePicture(file) spaceAmount = 10 for x in range(1,getWidth(source)): for y in range(spaceAmount,getHeight(source),spaceAmount): pix = getPixel(source,x,y) c = makeColor (0,0,0) setColor (pix, c) for x in range(spaceAmount,getWidth(source),spaceAmount): for y in range(1,getHeight(source)): pix = getPixel(source,x,y) c = makeColor (0,0,0) setColor (pix, c) show (source) def cropBanner(): # crop pixels 400 to 500 in the x direction # crop pixels 10 to 100 in the y direction # select picture to enlarge file = pickAFile() opict = makePicture (file) # get the width, heigh owid = getWidth (opict) ohgt = getHeight(opict) # determine width and height of reduced image nwid = 100 nhgt = 90 # create an empty image with the "reduced" dimensions npict = makeEmptyPicture(nwid, nhgt) # loop for the x and y positions from the original image for nx in range(1,nwid+1): for ny in range(1,nhgt+1): # determine pixels in new Picture ox = nx + 400 oy = ny + 10 # get pixel from original picture opixel = getPixel (opict, ox, oy) # get the pixel from the new picture npixel = getPixel (npict, nx, ny) # copy color from original pixel to new pixel c = getColor (opixel) setColor (npixel, c) show (opict) show (npict)