Crop the image
@return object
@param $x1 int
@param $y1 int
@param $x2 int
@param $y2 int
434149
function crop($x1,$y1,$x2,$y2) {
		$tmp=imagecreatetruecolor($width=$x2-$x1+1,$height=$y2-$y1+1);
		imagesavealpha($tmp,TRUE);
		imagefill($tmp,0,0,IMG_COLOR_TRANSPARENT);
		imagecopyresampled($tmp,$this->data,
			0,0,$x1,$y1,$width,$height,$width,$height);
		imagedestroy($this->data);
		$this->data=$tmp;
		return $this->save();
	}
638727
private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
        {
            $cropPoints = $this->getCropPoints($optimalWidth, $optimalHeight, $newWidth, $newHeight);

            // Find center - this will be used for the crop.
            $cropStartX = $cropPoints['x'];
            $cropStartY = $cropPoints['y'];

            $crop = $this->imageResized;

            $destOffsetX        = max(0, -$cropStartX);
            $destOffsetY        = max(0, -$cropStartY);
            $cropStartX         = max(0, $cropStartX);
            $cropStartY         = max(0, $cropStartY);
            $destWidth          = min($optimalWidth, $newWidth);
            $destHeight         = min($optimalHeight, $newHeight);

            // Now crop from center to exact requested size.
            $this->imageResized = imagecreatetruecolor($newWidth, $newHeight);

            imagealphablending($crop, true);
            imagealphablending($this->imageResized, false);
            imagesavealpha($this->imageResized, true);

            imagefilledrectangle(
                $this->imageResized,
                0,
                0,
                $newWidth,
                $newHeight,
                imagecolorallocatealpha(
                    $this->imageResized,
                    255,
                    255,
                    255,
                    127
               )
           );

            imagecopyresampled($this->imageResized, $crop, $destOffsetX, $destOffsetY, $cropStartX, $cropStartY, $destWidth, $destHeight, $destWidth, $destHeight);

            return true;
        }
1252707
private function crop(array $params)
    {
        $x = (isset($params['x']) && is_numeric($params['x'])) ? $params['x'] : 0;
        $y = (isset($params['y']) && is_numeric($params['y'])) ? $params['y'] : 0;

        $width = (isset($params['width']) && is_numeric($params['width'])) ? $params['width'] : null;
        $height = (isset($params['height']) && is_numeric($params['height'])) ? $params['height'] : null;

        if (is_null($width) || is_null($height)) {
            throw new Exception('Wrong crop width or height');
        }

        $this->image->crop(new Point($x, $y), new Box($width, $height));
    }
849841
public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null)
    {
        $this->convertCoordinatesFromUserSpace($x1, $y1);
        $this->convertCoordinatesFromUserSpace($x2, $y2);
        list($y1, $y2) = array($y2, $y1);
        return parent::drawEllipse($x1, $y1, $x2, $y2, $param5, $param6, $param7);
    }
776597
public function crop ($startX, $startY, $cropWidth, $cropHeight)
	{
		// validate input
		if (!is_numeric($startX))
		{
			throw new InvalidArgumentException('$startX must be numeric');
		}
		
		if (!is_numeric($startY))
		{
			throw new InvalidArgumentException('$startY must be numeric');
		}
		
		if (!is_numeric($cropWidth))
		{
			throw new InvalidArgumentException('$cropWidth must be numeric');
		}
		
		if (!is_numeric($cropHeight))
		{
			throw new InvalidArgumentException('$cropHeight must be numeric');
		}
		
		// do some calculations
		$cropWidth	= ($this->currentDimensions['width'] < $cropWidth) ? $this->currentDimensions['width'] : $cropWidth;
		$cropHeight = ($this->currentDimensions['height'] < $cropHeight) ? $this->currentDimensions['height'] : $cropHeight;
		
		// ensure everything's in bounds
		if (($startX + $cropWidth) > $this->currentDimensions['width'])
		{
			$startX = ($this->currentDimensions['width'] - $cropWidth);
			
		}
		
		if (($startY + $cropHeight) > $this->currentDimensions['height'])
		{
			$startY = ($this->currentDimensions['height'] - $cropHeight);
		}
		
		if ($startX < 0) 
		{
			$startX = 0;
		}
		
	    if ($startY < 0) 
		{
			$startY = 0;
		}
		
		// create the working image
		if (function_exists('imagecreatetruecolor'))
		{
			$this->workingImage = imagecreatetruecolor($cropWidth, $cropHeight);
		}
		else
		{
			$this->workingImage = imagecreate($cropWidth, $cropHeight);
		}
		
		$this->preserveAlpha();
		
		imagecopyresampled
		(
			$this->workingImage,
			$this->oldImage,
			0,
			0,
			$startX,
			$startY,
			$cropWidth,
			$cropHeight,
			$cropWidth,
			$cropHeight
		);
		
		$this->oldImage 					= $this->workingImage;
		$this->currentDimensions['width'] 	= $cropWidth;
		$this->currentDimensions['height'] 	= $cropHeight;
		
		return $this;
	}
803675
public function square_crop($size = null)
    {

        // Calculate measurements
        if ($this->width > $this->height) {
            // Landscape
            $x_offset = ($this->width - $this->height) / 2;
            $y_offset = 0;
            $square_size = $this->width - ($x_offset * 2);
        } else {
            // Portrait
            $x_offset = 0;
            $y_offset = ($this->height - $this->width) / 2;
            $square_size = $this->height - ($y_offset * 2);
        }

        // Trim to square
        $this->crop($x_offset, $y_offset, $x_offset + $square_size, $y_offset + $square_size);

        // Resize
        if ($size) {
            $this->resize($size, $size);
        }

        return $this;

    }
184307
def _crop_image(image, left=0, top=0, right=0, bottom=0, **kwargs):
    ''' 

    '''
    return image.crop((left, top, right, bottom))
1027059
public static function fromVector($x0, $y0, $x1, $y1) 
    {
        $line = new ImagickRendererLine();

        $line->Px = $x0;
        $line->Py = $y0;
        
        $line->rx = $x1 - $x0;
        $line->ry = $y1 - $y0;

        return $line;
    }
51886
public function crop(&$source, $target, array $action)
    {
        list($x1, $y1, $x2, $y2) = $action['value'];

        if ($this->image->set($source)->crop($x1, $y1, $x2, $y2)->save($target)) {
            $source = $target;
            return true;
        }

        return false;
    }
239626
def _cropbox(self, image, x, y, x2, y2):
        
        image['options']['crop'] = '%sx%s+%s+%s' % (x2 - x, y2 - y, x, y)
        image['size'] = (x2 - x, y2 - y)  # update image size
        return image
401898
public function getAngle($X1, $Y1, $X2, $Y2)
    {
        $Opposite = $Y2 - $Y1;
        $Adjacent = $X2 - $X1;
        $Angle = rad2deg(atan2($Opposite, $Adjacent));

        return $Angle > 0 ? $Angle : 360 - abs($Angle);
    }
793088
def cropped(self, t0, t1):
        """"""
        return Line(self.point(t0), self.point(t1))
865183
public function crop() {

		$args = func_get_args();
		
		$srcAspectRatio = $this->srcWidth / $this->srcHeight;
		
		// single float value given, represents aspect ratio of cropped image

		if(count($args) === 1) {

			if(!is_numeric($args[0]) || $args[0] <= 0) {
				throw new ImageModifierException('Invalid dimension(s) for cropping: ' . $args[0] . '.');
			}
		
			if($srcAspectRatio <= $args[0]) {
		
				// width determines

				$left = $right = 0;

				if($srcAspectRatio >= 1) {

				    // assume landscape

                    $top = $bottom = round(($this->srcHeight - $this->srcWidth / $args[0]) / 2);

                }

				else {

				    // assume portrait and shift crop somewhat up

                    $top = round(($this->srcHeight - $this->srcWidth / $args[0]) / 3);
                    $bottom	= round(($this->srcHeight - $this->srcWidth / $args[0]) * 2 / 3);

                }
			}

			else {
		
				// height determines

				$top = $bottom = 0;
				$left = $right = round(($this->srcWidth - $this->srcHeight * $args[0]) / 2);
			}
		}
		
		// width and height given
		
		else if(count($args) === 2) {

			$width	= (int) $args[0];
			$height	= (int) $args[1];
		
			if($width > 0 && $height > 0) {
				$left = $right = round(($this->srcWidth - $width) / 2);
		
				if($srcAspectRatio >= 1) {

					// landscape

					$top = $bottom = round(($this->srcHeight - $height) / 2);
				}

				else {

					// portrait and shift crop up

					$top	= round(($this->srcHeight - $height) / 3);
					$bottom	= round(($this->srcHeight - $height) * 2 / 3);
				}
			}
		
			else {
				throw new ImageModifierException('Invalid dimension(s) for cropping: ' . $width . ', ' . $height . '.');
			}
		}
		
		// top, left, bottom, right
		
		else if(count($args) == 4) {

			$top	= (int) $args[0];
			$left	= (int) $args[1];
			$bottom	= (int) $args[2];
			$right	= (int) $args[3];

		}

		else {
			throw new ImageModifierException('Insufficient arguments for cropping.');
		}
		
		// skip queuing when there is nothing to crop
		
		if(!$top && !$bottom && !$left && !$right) {

			return;

		}

		$todo = new \stdClass();
		
		$todo->method		= __FUNCTION__;
		$todo->parameters	= array($top, $right, $bottom, $left);

		$this->queue[] = $todo;
		
		$this->srcWidth		= $this->srcWidth - $left - $right;
		$this->srcHeight	= $this->srcHeight - $top - $bottom;

	}
447809
public function crop(array $options = []) {
		if (empty($options['height']) || empty($options['width'])) {
			throw new \InvalidArgumentException('You have to pass height and width in the options!');
		}

		$defaults = [
			'cropX' => 0,
			'cropY' => 0
		];

		$options = array_merge($defaults, $options);

		$this->_image->crop(
			new Point($options['cropX'], $options['cropY']),
			new Box($options['width'], $options['height'])
		);
		return $this;
	}
1097989
def cropped(self, t0, t1):
        """"""
        if abs(self.delta*(t1 - t0)) <= 180:
            new_large_arc = 0
        else:
            new_large_arc = 1
        return Arc(self.point(t0), radius=self.radius, rotation=self.rotation,
                   large_arc=new_large_arc, sweep=self.sweep,
                   end=self.point(t1), autoscale_radius=self.autoscale_radius)
371612
public static function atan2($y, $x)
    {
        $y = $y instanceof Angle ? $y->rad : $y;
        $x = $x instanceof Angle ? $x->rad : $x;

        return static::rad(atan2($y, $x));
    }
729927
public static function create($x, $y)
	{
		$point = new Point();
		$point->x = $x;
		$point->y = $y;
		return $point;
	}