code: def crop(img, patch, position):
      """Crop the input image into given size at given position.
  
      Args:
          patch(tuple): width and height of the patch
          position(list(str)): left_top, left_bottom, right_top, right_bottom
          and center.
      """
      if img.size[0] < patch[0]:
          raise Exception(
              "img size[0] %d is smaller than patch[0]: %d"
              % (img.size[0], patch[0])
          )
      if img.size[1] < patch[1]:
          raise Exception(
              "img size[1] %d is smaller than patch[1]: %d"
              % (img.size[1], patch[1])
          )
  
      if position == "left_top":
          left, upper = 0, 0
      elif position == "left_bottom":
          left, upper = 0, img.size[1] - patch[1]
      elif position == "right_top":
          left, upper = img.size[0] - patch[0], 0
      elif position == "right_bottom":
          left, upper = img.size[0] - patch[0], img.size[1] - patch[1]
      elif position == "center":
          left, upper = (img.size[0] - patch[0]) // 2, (
              img.size[1] - patch[1]
          ) // 2
      else:
          raise Exception("position is wrong")
  
      box = (left, upper, left + patch[0], upper + patch[1])
      new_img = img.crop(box)
      # print "crop to box %d,%d,%d,%d" % box
      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 2 for calling a global function with example usage: crop(img, patch, position) and returns: new_img