code: def crop_and_resize(img, patch, position):
      """Crop a max square patch of the input image at given position and resize
      it into given size.
  
      Args:
          patch(tuple): width, height
          position(list(str)): left, center, right, top, middle, bottom.
      """
      size = img.size
      if position == "left":
          left, upper = 0, 0
          right, bottom = size[1], size[1]
      elif position == "center":
          left, upper = (size[0] - size[1]) // 2, 0
          right, bottom = (size[0] + size[1]) // 2, size[1]
      elif position == "right":
          left, upper = size[0] - size[1], 0
          right, bottom = size[0], size[1]
      elif position == "top":
          left, upper = 0, 0
          right, bottom = size[0], size[0]
      elif position == "middle":
          left, upper = 0, (size[1] - size[0]) // 2
          right, bottom = size[0], (size[1] + size[0]) // 2
      elif position == "bottom":
          left, upper = 0, size[1] - size[0]
          right, bottom = size[0], size[1]
      else:
          raise Exception("position is wrong")
      box = (left, upper, right, bottom)
      new_img = img.crop(box)
  
      new_img = new_img.resize(patch, Image.BILINEAR)
      # print box+crop
      # print "crop to box %d,%d,%d,%d and scale to %d,%d" % (box+crop)
      return new_img
  
imports: from __future__ import division
  from builtins import range
  from builtins import object
  import random
  import numpy
  from PIL import Image, ImageEnhance
  import math
label_desc: Use image node_id 3 for calling a global function with example usage: crop_and_resize(img, patch, position) and returns: new_img