Get largest rectangle after rotation.
        http://stackoverflow.com/questions/16702966/rotate-image-and-crop-out-black-borders
549343
def largest_rotated_rect(w, h, angle):
        
        angle = angle / 180.0 * math.pi
        if w <= 0 or h <= 0:
            return 0, 0

        width_is_longer = w >= h
        side_long, side_short = (w, h) if width_is_longer else (h, w)

        # since the solutions for angle, -angle and 180-angle are all the same,
        # if suffices to look at the first quadrant and the absolute values of sin,cos:
        sin_a, cos_a = abs(math.sin(angle)), abs(math.cos(angle))
        if side_short <= 2. * sin_a * cos_a * side_long:
            # half constrained case: two crop corners touch the longer side,
            #   the other two corners are on the mid-line parallel to the longer line
            x = 0.5 * side_short
            wr, hr = (x / sin_a, x / cos_a) if width_is_longer else (x / cos_a, x / sin_a)
        else:
            # fully constrained case: crop touches all 4 sides
            cos_2a = cos_a * cos_a - sin_a * sin_a
            wr, hr = (w * cos_a - h * sin_a) / cos_2a, (h * cos_a - w * sin_a) / cos_2a
        return int(np.round(wr)), int(np.round(hr))
1192461
function _getBoundingRect (rects) {
  var bounds = {
    left: Number.POSITIVE_INFINITY,
    top: Number.POSITIVE_INFINITY,
    right: Number.NEGATIVE_INFINITY,
    bottom: Number.NEGATIVE_INFINITY,
    width: Number.NaN,
    height: Number.NaN
  }

  forEach(rects, function (rect) {
    if (rect.left < bounds.left) {
      bounds.left = rect.left
    }
    if (rect.top < bounds.top) {
      bounds.top = rect.top
    }
    if (rect.left + rect.width > bounds.right) {
      bounds.right = rect.left + rect.width
    }
    if (rect.top + rect.height > bounds.bottom) {
      bounds.bottom = rect.top + rect.height
    }
  })
  bounds.width = bounds.right - bounds.left
  bounds.height = bounds.bottom - bounds.top
  return bounds
}
1365516
public Rectangle getMaxRectabgle(){
		return new Rectangle((int)xLB.max, (int)yLB.max, (int)(xUB.max - xLB.max), (int)(yUB.max - yLB.max));
	}
350441
function getCropper(name) {
  // See http://sharp.dimens.io/en/stable/api-resize/#crop
  //
  // Possible attributes of sharp.gravity are north, northeast, east, southeast, south,
  // southwest, west, northwest, center and centre.
  if (sharp.gravity[name] !== undefined) {
    return sharp.gravity[name];
  }
  // The experimental strategy-based approach resizes so one dimension is at its target
  // length then repeatedly ranks edge regions, discarding the edge with the lowest
  // score based on the selected strategy.
  // - entropy: focus on the region with the highest Shannon entropy.
  // - attention: focus on the region with the highest luminance frequency,
  //   colour saturation and presence of skin tones.
  if (sharp.strategy[name] !== undefined) {
    return sharp.strategy[name];
  }

  throw new UsageError(
    `"${name}" is not a valid crop value. Consult http://sharp.dimens.io/en/stable/api-resize/#crop`
  );
}
651743
public function getGeoLocation()
	{
		if (!$this->checkPackageRequirements('exif'))
		{
			$this->setError(\Lang::txt('You need the PHP exif library installed to rotate image based on Exif Orientation value.'));
			return false;
		}

		try
		{
			$this->exif_data = exif_read_data($this->source);
		}
		catch (Exception $e)
		{
			$this->exif_data = array();
		}

		if (isset($this->exif_data['GPSLatitude']))
		{
			$lat      = $this->exif_data['GPSLatitude'];
			$lat_dir  = $this->exif_data['GPSLatitudeRef'];
			$long     = $this->exif_data['GPSLongitude'];
			$long_dir = $this->exif_data['GPSLongitudeRef'];

			$latitude  = $this->geo_single_fracs2dec($lat);
			$longitude = $this->geo_single_fracs2dec($long);
			$latitude_formatted  = $this->geo_pretty_fracs2dec($lat) . $lat_dir;
			$longitude_formatted = $this->geo_pretty_fracs2dec($long) . $long_dir;

			if ($lat_dir == 'S')
			{
				$latitude *= -1;
			}

			if ($long_dir == 'W')
			{
				$longitude *= -1;
			}

			$geo = array(
				'latitude'  => $latitude,
				'longitude' => $longitude,
				'latitude_formatted'  => $latitude_formatted,
				'longitude_formatted' => $longitude_formatted
			);
		}
		else
		{
			$geo = array();
		}

		return $geo;
	}
797903
def get_bbox(self):
        """"""

        width = self.width
        height = self.height

        cos_angle = cos(self.angle)
        sin_angle = sin(self.angle)

        x_diff = 0.5 * width
        y_diff = 0.5 * height

        # self rotates around (0, 0).
        c_x_diff = cos_angle * x_diff
        s_x_diff = sin_angle * x_diff

        c_y_diff = cos_angle * y_diff
        s_y_diff = sin_angle * y_diff

        if cos_angle > 0:
            if sin_angle > 0:
                x_max = c_x_diff + s_y_diff
                x_min = -x_max
                y_max = c_y_diff + s_x_diff
                y_min = -y_max
            else:  # sin_angle <= 0.0
                x_max = c_x_diff - s_y_diff
                x_min = -x_max
                y_max = c_y_diff - s_x_diff
                y_min = -y_max

        else:  # cos(angle) <= 0.0
            if sin_angle > 0:
                x_min = c_x_diff - s_y_diff
                x_max = -x_min
                y_min = c_y_diff - s_x_diff
                y_max = -y_min
            else:  # sin_angle <= 0.0
                x_min = c_x_diff + s_y_diff
                x_max = -x_min
                y_min = c_y_diff + s_x_diff
                y_max = -y_min

        return x_min, x_max, y_min, y_max
256322
public Rectangle getMinRectabgle(){
		return new Rectangle((int)xLB.min, (int)yLB.min, (int)(xUB.min - xLB.min), (int)(yUB.min - yLB.min));
	}
530986
private function getOptimalCrop($newWidth, $newHeight)
		# Author:     Jarrod Oberto
		# Date:       17-11-09
		# Purpose:    Get optimal crop dimensions
		# Param in:   width and height as requested by user (fig 3)
		# Param out:  Array of optimal width and height (fig 2)
		# Reference:
		# Notes:      The optimal width and height return are not the same as the
		#       same as the width and height passed in. For example:
		#
		#
		#   |-----------------|     |------------|       |-------|
		#   |             |   =>  |**|      |**|   =>  |       |
		#   |             |     |**|      |**|       |       |
		#   |           |       |------------|       |-------|
		#   |-----------------|
		#        original                optimal             crop
		#              size                   size               size
		#  Fig          1                      2                  3
		#
		#       300 x 250           150 x 125          150 x 100
		#
		#    The optimal size is the smallest size (that is closest to the crop size)
		#    while retaining proportion/ratio.
		#
		#  The crop size is the optimal size that has been cropped on one axis to
		#  make the image the exact size specified by the user.
		#
		#               * represent cropped area
		#
	{

		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

			// *** ...check if actual size is less than target size
			if ($this->width < $newWidth && $this->height < $newHeight)
			{
				return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
			}
		}

		$heightRatio = $this->height / $newHeight;
		$widthRatio = $this->width / $newWidth;

		if ($heightRatio < $widthRatio)
		{
			$optimalRatio = $heightRatio;
		}
		else
		{
			$optimalRatio = $widthRatio;
		}

		$optimalHeight = round($this->height / $optimalRatio);
		$optimalWidth = round($this->width / $optimalRatio);

		return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
	}
471312
public static int Maximum(ImageSource fastBitmap, int startX, int startY, int width, int height) {
        int max = 0;

        if (fastBitmap.isGrayscale()) {
            for (int i = startX; i < height; i++) {
                for (int j = startY; j < width; j++) {
                    int gray = fastBitmap.getRGB(j, i);
                    if (gray > max) {
                        max = gray;
                    }
                }
            }
        } else {
            for (int i = startX; i < height; i++) {
                for (int j = startY; j < width; j++) {
                    int gray = fastBitmap.getG(j, i);
                    if (gray > max) {
                        max = gray;
                    }
                }
            }
        }

        return max;
    }
1023698
def get_rectangle(self):
        
        rec = [self.pos[0], self.pos[1]]*2
        for age in self.nodes:
            for node in age:
                # Check max/min for x/y coords
                for i in range(2):
                    if rec[0+i] > node.pos[i]:
                        rec[0+i] = node.pos[i]
                    elif rec[2+i] < node.pos[i]:
                        rec[2+i] = node.pos[i]
        return tuple(rec)
669747
private String getCrop() {

        CmsImagePreviewHandler handler = getImagePreviewHandler();
        if (handler != null) {
            CmsCroppingParamBean crop = handler.getCroppingParam();
            if ((crop != null) && crop.isCropped()) {
                return "" + crop.getCropWidth() + " x " + crop.getCropHeight();
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
202071
public float getImageRotation() {
		double d = 2.0 * Math.PI;
		float rot = (float) ((rotationRadians - initialRotation) % d);
		if (rot < 0) {
			rot += d;
		}
        return rot;
    }
245259
function(e) {
        var dx,
            dy,
            rot = this.rotation * DEG_TO_RAD,
            points = this.map.points;

        // Depending on the change of axis, move the corners of the rectangle appropriately
        if (e.axis === "w") {
            if (rot) {
                dx = e.amount * Math.cos(rot);
                dy = e.amount * Math.sin(rot);
            } else {
                dx = e.amount;
                dy = 0;
            }

            // "top right" point shifts on change of w
            points[2] += dx;
            points[3] += dy;
        } else {
            if (rot) {
                dy = e.amount * Math.cos(rot);
                dx = -e.amount * Math.sin(rot);
            } else {
                dx = 0;
                dy = e.amount;
            }

            // "bottom left" point shifts on change of h
            points[6] += dx;
            points[7] += dy;
        }

        // "bottom right" point shifts on either change
        points[4] += dx;
        points[5] += dy;
    }
7126
private Rectangle fixRectangle(Rectangle rectangle, int baseWidth, int baseHeight) {
		if (this.positionBaseCentre) {
			// 修正图片位置从背景的中心计算
			rectangle.setLocation(//
					rectangle.x + (int) (Math.abs(baseWidth - rectangle.width) / 2), //
					rectangle.y + (int) (Math.abs(baseHeight - rectangle.height) / 2)//
			);
		}
		return rectangle;
	}
1098910
boolean rotateLargestFootprint3D(Dimension dimension) {
		return rotateLargestFootprint3D(dimension.getWidth(), dimension.getDepth(), dimension.getHeight());
	}
1040235
function getIntersectRect() {
  let n = arguments.length;

  if (!assert(n > 0, 'This method requires at least 1 argument specified.')) return null;

  let rect = {};
  let currRect, nextRect;

  for (let i = 0; i < n; i++) {
    if (!currRect) currRect = getRect(arguments[i]);

    if (!assert(currRect, 'Invalid computed rect.')) return null;

    if (i === 0 && ((i + 1) === n)) {
      nextRect = getRect(window);
    }
    else if ((i + 1) < n) {
      nextRect = getRect(arguments[i + 1]);
    }
    else {
      break;
    }

    if (!assert(nextRect, 'Invalid computed rect.')) return null;

    rect.width = Math.max(0.0, Math.min(currRect.right, nextRect.right) - Math.max(currRect.left, nextRect.left));
    rect.height = Math.max(0.0, Math.min(currRect.bottom, nextRect.bottom) - Math.max(currRect.top, nextRect.top));
    rect.top = Math.max(currRect.top, nextRect.top);
    rect.left = Math.max(currRect.left, nextRect.left);
    rect.bottom = rect.top + rect.height;
    rect.right = rect.left + rect.width;

    if (rect.width * rect.height === 0) {
      rect.width = 0;
      rect.height = 0;
      rect.top = 0;
      rect.left = 0;
      rect.bottom = 0;
      rect.right = 0;
    }

    currRect = rect;
  }

  return rect;
}
695600
def rotate_img(im, deg, mode=cv2.BORDER_CONSTANT, interpolation=cv2.INTER_AREA):
    
    r,c,*_ = im.shape
    M = cv2.getRotationMatrix2D((c//2,r//2),deg,1)
    return cv2.warpAffine(im,M,(c,r), borderMode=mode, flags=cv2.WARP_FILL_OUTLIERS+interpolation)