@@ -0,0 +1,1381 @@
+import os%0Aimport cv2%0A%0Adef crop_landscape(image, dim):%0A  r = (dim%5B0%5D / image.shape%5B0%5D) / (dim%5B0%5D / dim%5B1%5D)%0A  nw = int(image.shape%5B1%5D * r)%0A%0A  resized = cv2.resize(image, (nw, int(dim%5B1%5D)), interpolation=cv2.INTER_AREA)%0A%0A  half_width = int(dim%5B0%5D) / 2%0A  half_shape_width = int(resized.shape%5B1%5D) / 2%0A%0A  start_x = half_shape_width - half_width%0A  end_x = half_width + half_shape_width%0A  cropped = resized%5B0:dim%5B1%5D, start_x:end_x%5D%0A%0A  return cropped%0A%0Adef crop_portrait(image, dim):%0A  r = dim%5B1%5D / image.shape%5B1%5D / (dim%5B1%5D / dim%5B0%5D)%0A  nh = int(image.shape%5B0%5D * r)%0A%0A  resized = cv2.resize(image, (int(dim%5B0%5D), nh), interpolation=cv2.INTER_AREA)%0A  half_height = int(dim%5B1%5D) / 2%0A  half_shape_height = int(resized.shape%5B0%5D) / 2%0A%0A  start_y = half_shape_height - half_height%0A  end_y = half_height + half_shape_height%0A  cropped = resized%5Bstart_y:end_y, 0:dim%5B0%5D%5D%0A%0A  return cropped%0A%0Adef create_other_size(image, file_name, dim, location):%0A  # 1 =%3E width index, 0 =%3E height index%0A  try:%0A      if image.shape%5B0%5D %3E image.shape%5B1%5D:%0A          cropped = crop_portrait(image, dim)%0A      else:%0A          cropped = crop_landscape(image, dim)%0A%0A      cv2.imwrite(os.path.join(location, file_name), cropped)%0A%0A  except Exception, ex:%0A      pass%0A%0Afile_name = '/home/user/picture.jpg'%0Aoutput_dir = '/home/user/output/'%0Aimage = cv2.imread(file_name)%0Acreate_other_size(image, file_name, (100.0, 100.0), output_dir)%0A

Create main.py