parameters: (image, width, height, halign='middle', valign='middle', top_crop_pct=None, bottom_crop_pct=None, left_crop_pct=None, right_crop_pct=None, post_crop_uniform_scale_pct=None)
return_statement: return image.execute_transforms()
docstring: From http://stackoverflow.com/questions/1944112/app-engine-cropping-to-a-specific-width-and-height
    
    Resize then optionally crop a given image.
  
    Attributes:
      image: The image
      width: The desired width
      height: The desired height
      halign: Acts like photoshop's 'Canvas Size' function, horizontally
              aligning the crop to left, middle or right
      valign: Verticallly aligns the crop to top, middle or bottom
      
      :post_crop_uniform_scale_pct:
          If not None, will scale image after cropping by the indicated percent. Should be None or a
          float between 0.0 and 1.0
docstring_summary: From http://stackoverflow.com/questions/1944112/app-engine-cropping-to-a-specific-width-and-height
    
    Resize then optionally crop a given image.
docstring_tokens: From http : // stackoverflow . com / questions / 1944112 / app - engine - cropping - to - a - specific - width - and - height Resize then optionally crop a given image .
function: def rescale(image, width, height, halign='middle', valign='middle', top_crop_pct=None, bottom_crop_pct=None, left_crop_pct=None, right_crop_pct=None, post_crop_uniform_scale_pct=None):
    """
    From http://stackoverflow.com/questions/1944112/app-engine-cropping-to-a-specific-width-and-height
    
    Resize then optionally crop a given image.
  
    Attributes:
      image: The image
      width: The desired width
      height: The desired height
      halign: Acts like photoshop's 'Canvas Size' function, horizontally
              aligning the crop to left, middle or right
      valign: Verticallly aligns the crop to top, middle or bottom
      
      :post_crop_uniform_scale_pct:
          If not None, will scale image after cropping by the indicated percent. Should be None or a
          float between 0.0 and 1.0
  
    """
    #image = images.Image(img_data)
    
    #logging.info(left_crop_pct)
    
    if top_crop_pct is not None and bottom_crop_pct is not None:
      if left_crop_pct is not None and right_crop_pct is not None:
          image.crop(left_crop_pct,top_crop_pct,right_crop_pct,bottom_crop_pct)
      else:
          image.crop(0.0,top_crop_pct,1.0,bottom_crop_pct)
    elif left_crop_pct is not None and right_crop_pct is not None:
      image.crop(left_crop_pct,0.0,right_crop_pct,1.0)
  
    desired_wh_ratio = float(width) / float(height)
    wh_ratio = float(image.width) / float(image.height)
  
    if desired_wh_ratio > wh_ratio:
      # resize to width, then crop to height
      image.resize(width=width)
      output = image.execute_transforms()
      if image.width < width or image.height < height:
          return output
      trim_y = (float(image.height - height) / 2) / image.height
      if valign == 'top':
        image.crop(0.0, 0.0, 1.0, 1 - (2 * trim_y))
      elif valign == 'bottom':
  #      logging.info('----------')
  #      logging.info(image.height)
  #      logging.info(image.width)
  #      logging.info(height)
  #      logging.info(trim_y)
        image.crop(0.0, (2 * trim_y), 1.0, 1.0)
      else:
        image.crop(0.0, trim_y, 1.0, 1 - trim_y)
    else:
      # resize to height, then crop to width
      image.resize(height=height)
      output = image.execute_transforms()
      if image.width < width or image.height < height:
          return output
      trim_x = (float(image.width - width) / 2) / image.width
      if halign == 'left':
        image.crop(0.0, 0.0, 1 - (2 * trim_x), 1.0)
      elif halign == 'right':
        image.crop((2 * trim_x), 0.0, 1.0, 1.0)
      else:
        image.crop(trim_x, 0.0, 1 - trim_x, 1.0)
  
    return image.execute_transforms()
function_tokens: def rescale ( image , width , height , halign = 'middle' , valign = 'middle' , top_crop_pct = None , bottom_crop_pct = None , left_crop_pct = None , right_crop_pct = None , post_crop_uniform_scale_pct = None ) : #image = images.Image(img_data) #logging.info(left_crop_pct) if top_crop_pct is not None and bottom_crop_pct is not None : if left_crop_pct is not None and right_crop_pct is not None : image . crop ( left_crop_pct , top_crop_pct , right_crop_pct , bottom_crop_pct ) else : image . crop ( 0.0 , top_crop_pct , 1.0 , bottom_crop_pct ) elif left_crop_pct is not None and right_crop_pct is not None : image . crop ( left_crop_pct , 0.0 , right_crop_pct , 1.0 ) desired_wh_ratio = float ( width ) / float ( height ) wh_ratio = float ( image . width ) / float ( image . height ) if desired_wh_ratio > wh_ratio : # resize to width, then crop to height image . resize ( width = width ) output = image . execute_transforms ( ) if image . width < width or image . height < height : return output trim_y = ( float ( image . height - height ) / 2 ) / image . height if valign == 'top' : image . crop ( 0.0 , 0.0 , 1.0 , 1 - ( 2 * trim_y ) ) elif valign == 'bottom' : #      logging.info('----------') #      logging.info(image.height) #      logging.info(image.width) #      logging.info(height) #      logging.info(trim_y) image . crop ( 0.0 , ( 2 * trim_y ) , 1.0 , 1.0 ) else : image . crop ( 0.0 , trim_y , 1.0 , 1 - trim_y ) else : # resize to height, then crop to width image . resize ( height = height ) output = image . execute_transforms ( ) if image . width < width or image . height < height : return output trim_x = ( float ( image . width - width ) / 2 ) / image . width if halign == 'left' : image . crop ( 0.0 , 0.0 , 1 - ( 2 * trim_x ) , 1.0 ) elif halign == 'right' : image . crop ( ( 2 * trim_x ) , 0.0 , 1.0 , 1.0 ) else : image . crop ( trim_x , 0.0 , 1 - trim_x , 1.0 ) return image . execute_transforms ( )