Resize helper function.

@param Image $image
@param int $newWidth
@param int $newHeight
@param int $targetX
@param int $targetY
@param int $srcX
@param int $srcY
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()
            );

        }
    }
842635
public function refit(ImageInterface $image): void
    {
        $this->x = 0;
        $this->y = 0;

        $ratio = $this->getWidth() / $image->getWidth();
        $this->setWidth($image->getWidth());
        $this->setHeight($this->getHeight() / $ratio);

        if ($this->getHeight() > $image->getHeight()) {
            $ratio = $this->getHeight() / $image->getHeight();
            $this->setWidth($this->getWidth() / $ratio);
            $this->setHeight($image->getHeight());
        }
    }
1341255
protected function resizeImage($path, $width, $height)
    {
        $this->images->open('Gd',$path);
        $this->images->resize($width, $height);
    }
1286091
protected function resizePortrait(ImageInterface $image, $width, $height)
    {
        // @codeCoverageIgnoreStart
        if (empty($height)) {
            throw new InvalidArgumentException(
                'Height value for portrait resize is empty. This may be caused by unfixed EXIF-rotated images'
            );
        }
        // @codeCoverageIgnoreEnd

        $optimalWidth = $this->getSizeByFixedHeight($image, $height);

        $dimensions = $image->getSize()
            ->heighten($height)
            ->widen($optimalWidth);

        $image = $image->resize($dimensions);

        return $image;
    }
1047761
public static function resizeImage($image, $newWidth, $newHeight, $autoRotate = false, $mode = ImageTools::MODE_SCALE_CROP, $backgroundColor = 0x00000000)
    {
        $sourceWidth = imagesx($image);
        $sourceHeight = imagesy($image);

        $sourcePar = $sourceWidth / $sourceHeight;
        $newPar = $newWidth / $newHeight;
        $sourceX = $newX = 0;
        $sourceY = $newY = 0;

        if ($autoRotate && (($sourcePar > 1 && $newPar < 1) || ($sourcePar < 1 && $newPar > 1))) {
            $t = $newWidth;
            $newWidth = $newHeight;
            $newHeight = $t;
            $newPar = $newWidth / $newHeight;
        }

        $targetWidth = $newWidth;
        $targetHeight = $newHeight;

        // MODE_EXACT gets handled through default variables

        if ($mode == ImageTools::MODE_CROP) {
            if ($sourceWidth > $newWidth) {
                $sourceX = ($sourceWidth - $newWidth) >> 1;
                $sourceWidth = $newWidth;
            } else {
                $targetWidth = $sourceWidth;
                $newX = ($newWidth - $sourceWidth) >> 1;
            }

            if ($sourceHeight > $newHeight) {
                $sourceY = ($sourceHeight - $newHeight) >> 1;
                $sourceHeight = $newHeight;
            } else {
                $targetHeight = $sourceHeight;
                $newY = ($newHeight - $sourceHeight) >> 1;
            }

        } elseif ($mode == ImageTools::MODE_SCALE_CROP) {
            if ($sourcePar > $newPar) {
                $orgWidth = $sourceWidth;
                $sourceWidth = $sourceHeight * $newPar;
                $sourceX = ($orgWidth - $sourceWidth) >> 1;
            } else {
                $orgHeight = $sourceHeight;
                $sourceHeight = $sourceWidth / $newPar;
                $sourceY = ($orgHeight - $sourceHeight) >> 1;
            }

        } elseif ($mode == ImageTools::MODE_SCALE_PAD) {
            if ($sourcePar > $newPar) {
                $targetHeight = $targetWidth / $sourcePar;
                $newY = ($newHeight - $targetHeight) >> 1;
            } else {
                $targetWidth = $targetHeight * $sourcePar;
                $newX = ($newWidth - $targetWidth) >> 1;
            }
        } elseif ($mode == ImageTools::MODE_FIT) {
            if ($sourcePar > $newPar) {
                $targetHeight = $newHeight = round($newWidth / $sourcePar);
            } else {
                $targetWidth = $newWidth = round($newHeight * $sourcePar);
            }
        }

        $new = imagecreatetruecolor($newWidth, $newHeight);

        imagealphablending($new, false);

        $backgroundColor = self::colorHexToRgba($backgroundColor);
        $backgroundColor = imagecolorallocatealpha($new, $backgroundColor['r'], $backgroundColor['g'], $backgroundColor['b'], 127 - floor($backgroundColor['a'] / 2));

        imagefilledrectangle($new, 0, 0, $newWidth, $newHeight, $backgroundColor);

        imagesavealpha($new, true);

        imagecopyresampled($new, $image, $newX, $newY, $sourceX, $sourceY, $targetWidth, $targetHeight, $sourceWidth, $sourceHeight);

        return $new;
    }
969356
private function setImageSize($image, $size, $needExactSize = false)
    {
        if (empty($size)) {
            return $image;
        }

        if ($needExactSize || $image->getImageWidth() > $size[0]) {
            if ($size[0] == 0 || $size[1] == 0) {
                $image->scaleImage($size[0], $size[1]);
            } else {
                $image->cropThumbnailImage($size[0], $size[1]);
            }
        }

        return $image;
    }
806037
public function resize($newWidth, $newHeight, $option = 'auto')
        {
            // Get optimal width and height - based on $option.
            $option_array = $this->get_dimensions($newWidth, $newHeight, $option);

            $optimalWidth  = $option_array['optimalWidth'];
            $optimalHeight = $option_array['optimalHeight'];

            // Resample - create image canvas of x, y size.
            $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
            $imageBackground = imagecreatetruecolor($this->width, $this->height);

            // Retain transparency for PNG and GIF files.
            $background_colour = imagecolorallocate(
                $imageBackground,
                arrayGet($this->config, 'background_color.r'),
                arrayGet($this->config, 'background_color.g'),
                arrayGet($this->config, 'background_color.b')
           );

            imagefilledrectangle($imageBackground, 0, 0, $this->width, $this->height, $background_colour);
            imagecopy($imageBackground, $this->image, 0, 0, 0, 0, $this->width, $this->height);
            // imagecolortransparent($this->imageResized, imagecolorallocatealpha($this->imageResized, 255, 255, 255, 127));
            // imagealphablending($this->imageResized, false);
            // imagesavealpha($this->imageResized, true);

            // convert transparency to white when converting from PNG to JPG.
            // PNG to PNG should retain transparency as per normal.
            // imagefill($this->imageResized, 0, 0, IMG_COLOR_TRANSPARENT);

            // Create the new image.
            imagecopyresampled($this->imageResized, $imageBackground, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);

            // if option is 'crop' or 'fit', then crop too.
            if ($option == 'crop' || $option == 'fit') {
                $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
            }

            // Return $this to allow calls to be chained.
            return $this;
        }
458287
protected function resizeExact(ImageInterface $image, $width, $height)
    {
        return $image->resize(new Box($width, $height));
    }
387118
public function resize($width, $height)
    {
        //if the width is not specified, make it relative to the height
        if($width == -1){

            $this->width['dest'] = ($height * $this->width['orig']) / $this->height['orig'];
            $this->height['dest'] = $height;

        //if the height is not specified, make it relative to the width
        } elseif ($height == -1){

            $this->width['dest'] = $width;
            $this->height['dest'] = ($width * $this->height['orig']) / $this->width['orig'];

        } else {

            $this->width['dest'] = $width;
            $this->height['dest'] = $height;
        }

        //set resize code depending on the type of image it is
        switch ($this->type)

    {
            case "gif":
                $this->edited = imagecreate($this->width['dest'], $this->height['dest']);

                imagecopyresampled($this->edited, $this->original, 0, 0, 0, 0, $this->width['dest'], $this->height['dest'], $this->width['orig'], $this->height['orig']);

            break;

            case "jpg":
                $this->edited = imagecreatetruecolor($this->width['dest'], $this->height['dest']);

                imagecopyresampled($this->edited, $this->original, 0, 0, 0, 0, $this->width['dest'], $this->height['dest'], $this->width['orig'], $this->height['orig']);


            break;

            case "png":

                $this->edited = imagecreatetruecolor ($this->width['dest'], $this->height['dest']);

                //preserve the alpha if exists
                imagealphablending($this->edited, false);
                imagesavealpha($this->edited, true);

                imagecopyresampled($this->edited, $this->original, 0, 0, 0, 0, $this->width['dest'], $this->height['dest'], $this->width['orig'], $this->height['orig']);

            break;
        }

    }
383990
public function runExpand(Image $image, $width, $color)
    {
        return $image->resizeCanvas(
            $width * 2,
            $width * 2,
            'center',
            true,
            $color
        );
    }
365413
public function getWidth(Image $image, $dpr, $width)
    {
        return (new Dimension($image, $dpr))->get($width);
    }
936540
public function resize(int $width = 0, int $height = 0)
    {
        if (!$width && !$height) {
            throw new ImageException('You must supply at least one dimension');
        }
        $iw = $this->info[0];
        $ih = $this->info[1];
        if (!$height || !$width) {
            if (!$width) {
                $width  = $height / $ih * $iw;
            }
            if (!$height) {
                $height = $width  / $iw * $ih;
            }
        }
        $di = imagecreatetruecolor($width, $height);
        imagecopyresized($di, $this->data, 0, 0, 0, 0, $width, $height, $iw, $ih);
        $this->data = $di;
    }
1212687
private function resize($newWidth, $newHeight, $srcImg, $filename)
    {
        $oldX = imagesx($srcImg);
        $oldY = imagesy($srcImg);

        if ($oldX > $oldY) {
            $thumbWidth = $newWidth;
            $thumbHeight = $oldY * ($newHeight / $oldX);
        } else {
            if ($oldX <= $oldY) {
                $thumbWidth = $oldX * ($newWidth / $oldY);
                $thumbHeight = $newHeight;
            }
        }

        //white background
        $dstImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
        $bg = imagecolorallocate($dstImg, 255, 255, 255);
        imagefill($dstImg, 0, 0, $bg);

        //resizing
        imagecopyresampled($dstImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $oldX, $oldY);
        $srcImg = imagepng($dstImg, $filename);

        //free memory
        imagedestroy($dstImg);
    }
1052805
public function resize($width, $height = NULL, $resizeMode = NULL)
    {
        if(!$height)
        {
            $height = $width;
        }

        $this->effect[] = new Resize($width, $height, $resizeMode);
    }
914723
public function runFillResize($image, $width, $height)
    {
        $image = $this->runMaxResize($image, $width, $height);

        return $image->resizeCanvas($width, $height, 'center');
    }
1311013
public function execute($image)
    {
        $width = $this->argument(0)->type('digit')->required()->value();
        $height = $this->argument(1)->type('digit')->value($width);
        $constraints = $this->argument(2)->type('closure')->value();
        $position = $this->argument(3)->type('string')->value('center');

        // calculate size
        $cropped = $image->getSize()->fit(new Size($width, $height), $position);
        $resized = clone $cropped;
        $resized = $resized->resize($width, $height, $constraints);

        // crop image
        $image->getCore()->cropImage(
            $cropped->width,
            $cropped->height,
            $cropped->pivot->x,
            $cropped->pivot->y
        );

        // resize image
        $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight());
        $image->getCore()->setImagePage(0,0,0,0);

        return true;
    }
680468
public function create($image, $thumbnailWidth = 100, $thumbnailHeight = 100)
    {
        $this->setupTargetPath($image);
        $this->setupTargetImage($image);

        $this->transformation->thumbnail(new Image\Box($thumbnailWidth, $thumbnailHeight))
                             ->apply($this->imagine->open($image))
                             ->save($this->thumbnailImage);

        $this->imageSize = getimagesize($this->thumbnailImage);
    }