Returns image size name, based on image height, weight and cropped flag
@param integer $targetWidth
@param integer $targetHeight
@param boolean $cropped
@return string
195899
public function getImageSizeName($targetWidth, $targetHeight, $cropped = false)
	{
		$sizeName = $targetWidth . 'x' . $targetHeight;
		if ($cropped) {
			$sizeName .= 'cropped';
		}

		return $sizeName;
	}
322328
private function _resize(&$image, $newWidth, $newHeight, $targetX = 0, $targetY = 0, $srcX = 0, $srcY = 0)
    {

//        $this->_imageCheck();

        if ($image->isAnimated()) { // Animated GIF
            $gift = new GifHelper();
            $blocks = $gift->resize($image->getBlocks(), $newWidth, $newHeight);
            // Resize image instance
            $image = new Image(
                $image->getCore(),
                $image->getImageFile(),
                $newWidth,
                $newHeight,
                $image->getType(),
                $blocks,
                true
            );
        } else {

            // Create blank image
            $newImage = Image::createBlank($newWidth, $newHeight);

            if (ImageType::PNG === $image->getType()) {
                // Preserve PNG transparency
                $newImage->fullAlphaMode(true);
            }

            imagecopyresampled(
                $newImage->getCore(),
                $image->getCore(),
                $targetX,
                $targetY,
                $srcX,
                $srcY,
                $newWidth,
                $newHeight,
                $image->getWidth(),
                $image->getHeight()
            );

            // Free memory of old resource
            imagedestroy($image->getCore());

            // Resize image instance
            $image = new Image(
                $newImage->getCore(),
                $image->getImageFile(),
                $newWidth,
                $newHeight,
                $image->getType()
            );

        }
    }
518897
public int getResultingHeight() {

        int height = getResultingTargetHeight();
        if (height == -1) {
            if (isCropped()) {
                height = m_cropHeight;
            } else {
                height = m_orgHeight;
            }
        }
        return height;
    }
241232
private function getDimensions($newWidth, $newHeight, $option)
		# Author:     Jarrod Oberto
		# Date:       17-11-09
		# Purpose:    Get new image dimensions based on user specificaions
		# Param in:   $newWidth:
		#             $newHeight:
		# Param out:  Array of new width and height values
		# Reference:
		# Notes:    If $option = 3 then this function is call recursivly
		#
		#       To clarify the $option input:
		#               0 = The exact height and width dimensions you set.
		#               1 = Whatever height is passed in will be the height that
		#                   is set. The width will be calculated and set automatically
		#                   to a the value that keeps the original aspect ratio.
		#               2 = The same but based on the width.
		#               3 = Depending whether the image is landscape or portrait, this
		#                   will automatically determine whether to resize via
		#                   dimension 1,2 or 0.
		#               4 = Resize the image as much as possible, then crop the
		#         remainder.
	{

		switch (strval($option))
		{
			case '0':
			case 'exact':
				$optimalWidth = $newWidth;
				$optimalHeight = $newHeight;
				break;
			case '1':
			case 'portrait':
				$dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '2':
			case 'landscape':
				$dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '3':
			case 'auto':
				$dimensionsArray = $this->getSizeByAuto($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '4':
			case 'crop':
				$dimensionsArray = $this->getOptimalCrop($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
		}

		return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
	}
768524
public function do_crop($width, $height, $offsetX = 0, $offsetY = 0)
    {
        $this->_image->cropImage($width, $height, $offsetX, $offsetY);
        $this->_image->setImagePage($width, $height, 0, 0);

        $this->_width = $this->_image->getImageWidth();
        $this->_height = $this->_image->getImageHeight();

        return $this;
    }
36392
private function getOptionName(TargetMethod $targetMethod): string
    {
        $name   = $targetMethod->paramName();
        $prefix = strlen($name) === 1 ? '-' : '--';
        $suffix = $targetMethod->requiresParameter() ? ' ' . $targetMethod->valueDescription() : '';
        return $prefix . $name . $suffix;
    }
1284034
private function getSizeByFixedWidth($newWidth, $newHeight)
	{
		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

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

		$ratio = $this->height / $this->width;

		$newHeight = $newWidth * $ratio;

		//return $newHeight;
		return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
	}
1059019
public function resize($crop = false)
    {
        if ($crop) {
            return $this->resizeCrop();
        } else {
            $sourceDimension = $this->sourceImageFile->getDimension();
            $resampleDimension = $this->resampleImageFile->getDimension();

            if (($sourceDimension->getWidth() <= $resampleDimension->getWidth()) && ($sourceDimension->getHeight() <= $resampleDimension->getHeight())) {
                return true;
            } //no resizing needed

            //try max width first...
            $resizeRatio = $resampleDimension->getWidth() / $sourceDimension->getWidth();
            $resizeWidth = $resampleDimension->getWidth();
            $resizeHeight = $sourceDimension->getHeight() * $resizeRatio;

            //if that didn't work
            if ($resizeHeight > $resampleDimension->getHeight()) {
                $resizeRatio = $resampleDimension->getHeight() / $sourceDimension->getHeight();
                $resizeHeight = $resampleDimension->getHeight();
                $resizeWidth = $sourceDimension->getWidth() * $resizeRatio;
            }

            if (function_exists('imagecreatetruecolor')) {
                $this->resampleImageResource = imagecreatetruecolor($resizeWidth, $resizeHeight);

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

                $transparent = imagecolorallocatealpha($this->resampleImageResource, 255, 255, 255, 127);
                imagefilledrectangle($this->resampleImageResource, 0, 0, $resampleDimension->getWidth(),
                    $resampleDimension->getHeight(), $transparent);

                return imagecopyresampled(
                    $this->resampleImageResource,
                    $this->sourceImageResource,
                    0,
                    0,
                    0,
                    0,
                    $resizeWidth,
                    $resizeHeight,
                    $sourceDimension->getWidth(),
                    $sourceDimension->getHeight()
                );
            } else {
                $this->resampleImageResource = imagecreate($resampleDimension->getWidth(),
                    $resampleDimension->getHeight());

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

                $transparent = imagecolorallocatealpha($this->resampleImageResource, 255, 255, 255, 127);
                imagefilledrectangle($this->resampleImageResource, 0, 0, $resampleDimension->getWidth(),
                    $resampleDimension->getHeight(), $transparent);

                return imagecopyresampled(
                    $this->resampleImageResource,
                    $this->sourceImageResource,
                    0,
                    0,
                    0,
                    0,
                    $resizeWidth,
                    $resizeHeight,
                    $sourceDimension->getWidth(),
                    $sourceDimension->getHeight()
                );
            }
        }
    }
4296
static public function getResizedImageSize($file, $target=25){
		list($width, $height, , ) = getimagesize($file);
		$max = max($width, $height);
		$rapp = $target / $max;
		$width = intval($rapp * $width);
		$height = intval($rapp * $height);
		return array($width, $height);
	}
899380
private function getSizeByAuto($newWidth, $newHeight)
        {
            // Image to be resized is wider (landscape).
            if ($this->height < $this->width) {
                $optimalWidth  = $newWidth;
                $optimalHeight = $this->getSizeByFixedWidth($newWidth);
            } else if ($this->height > $this->width) {
                $optimalWidth  = $this->getSizeByFixedHeight($newHeight);
                $optimalHeight = $newHeight;
            }  else {
                if ($newHeight < $newWidth)
                {
                    $optimalWidth  = $newWidth;
                    $optimalHeight = $this->getSizeByFixedWidth($newWidth);
                } else if ($newHeight > $newWidth) {
                    $optimalWidth  = $this->getSizeByFixedHeight($newHeight);
                    $optimalHeight = $newHeight;
                } else {
                    // Sqaure being resized to a square.
                    $optimalWidth  = $newWidth;
                    $optimalHeight = $newHeight;
                }
            }

            return array(
                'optimalWidth'     => $optimalWidth,
                'optimalHeight'    => $optimalHeight
           );
        }
1309516
private function getCropRectangle($image, $targetBox, $horzMode, $vertMode)
	{
		$imageBox = $image->getSize();
		$kw = $imageBox->getWidth() / $targetBox->getWidth();
		$kh = $imageBox->getHeight() / $targetBox->getHeight();
		$x = $y = $w = $h = 0;
		if($kh > $kw) {
			$x = 0;
			$w = $imageBox->getWidth();
			$h = $targetBox->getHeight() * $kw;
			switch ($vertMode) {
				case self::CROP_TOP:
					$y = 0;
					break;
				case self::CROP_BOTTOM:
					$y = $imageBox->getHeight() - $h;
					break;
				case self::CROP_CENTER:
					$y = ($imageBox->getHeight() - $h) / 2;
					break;
			}
		} else {
			$y = 0;
			$h = $imageBox->getHeight();
			$w  = $targetBox->getWidth() * $kh;
			switch ($horzMode) {
				case self::CROP_LEFT:
					$x = 0;
					break;
				case self::CROP_RIGHT:
					$x = $imageBox->getWidth() - $w;
					break;
				case self::CROP_CENTER:
					$x = ($imageBox->getWidth() - $w) / 2;
					break;
			}
		}
		return [$x, $y, $w, $h];
	}
559998
public function crop($width, $height, $allow_enlarge = false, $position = self::CROPCENTER)
    {
        if (!$allow_enlarge) {
            // this logic is slightly different to resize(),
            // it will only reset dimensions to the original
            // if that particular dimenstion is larger

            if ($width > $this->getSourceWidth()) {
                $width  = $this->getSourceWidth();
            }

            if ($height > $this->getSourceHeight()) {
                $height = $this->getSourceHeight();
            }
        }

        $ratio_source = $this->getSourceWidth() / $this->getSourceHeight();
        $ratio_dest = $width / $height;

        if ($ratio_dest < $ratio_source) {
            $this->resizeToHeight($height, $allow_enlarge);

            $excess_width = ($this->getDestWidth() - $width) / $this->getDestWidth() * $this->getSourceWidth();

            $this->source_w = $this->getSourceWidth() - $excess_width;
            $this->source_x = $this->getCropPosition($excess_width, $position);

            $this->dest_w = $width;
        } else {
            $this->resizeToWidth($width, $allow_enlarge);

            $excess_height = ($this->getDestHeight() - $height) / $this->getDestHeight() * $this->getSourceHeight();

            $this->source_h = $this->getSourceHeight() - $excess_height;
            $this->source_y = $this->getCropPosition($excess_height, $position);

            $this->dest_h = $height;
        }

        return $this;
    }
97389
private function verifySize($originalWidth, $originalHeight, $targetWidth, $targetHeight)
    {
        if ($originalWidth < $targetWidth && $originalHeight < $targetHeight) {
            return array(
                'width' => $originalWidth,
                'height' => $originalHeight,
            );
        }

        return array(
            'width' => $targetWidth,
            'height' => $targetHeight,
        );
    }
515042
protected function getSpecialOffset(\Imagick $original, $targetWidth, $targetHeight)
    {
        return $this->getRandomEdgeOffset($original, $targetWidth, $targetHeight);
    }
224056
public function setTargetSize($targetWidth, $targetHeight)
    {
        $this->targetWidth = $targetWidth;
        $this->targetHeight = $targetHeight;

        return $this;
    }
1049532
public static Image getScaledInstance(Image img, int targetWidth, int targetHeight) {
		final int type = BufferedImage.TYPE_INT_ARGB;
		Image ret = img;
		final int width = ret.getWidth(null);
		final int height = ret.getHeight(null);
		if (width != targetWidth && height != targetHeight) {
			// a priori plus performant que Image.getScaledInstance
			final BufferedImage scratchImage = new BufferedImage(targetWidth, targetHeight, type);
			final Graphics2D g2 = scratchImage.createGraphics();
			g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
					RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			g2.drawImage(ret, 0, 0, targetWidth, targetHeight, 0, 0, width, height, null);
			g2.dispose();
			ret = scratchImage;
		}
		return ret;
	}
846649
private function getMinTargetSize($w, $h)
    {
        extract($this->getInfo());

        if ($w > $width or $h > $height) {
            $w = $width;
            $h = $height;
        }

        if ($w > $h) {
            extract($this->getFilesize($w, 0));
        } else {
            extract($this->getFilesize(0, $h));
        }

        $this->targetSize = compact('width', 'height');
    }