Get width and heigth of an image resized in order fit a target size.

@param string $file The image to resize
@param int $target	The final max width/height
@return array array of ($width, $height). One of them must be $target
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);
	}
1285231
public function onAfterLoadIntoFile($file)
    {
        // return if not an image
        if (!$file->getIsImage()) {
            return;
        }

        // get parent folder path
        $folder = rtrim($file->Parent()->getFilename(), '/');

        $custom_folders = $this->config()->get('custom_folders');

        if (!empty($custom_folders[$folder]) && is_array($custom_folders[$folder])) {
            foreach ($custom_folders[$folder] as $key => $val) {
                $this->config()->set($key, $val);
            }
        }

        if ($this->config()->get('bypass')) {
            return;
        }

        $this->config_max_width = $this->config()->get('max_width');
        $this->config_max_height = $this->config()->get('max_height');
        $this->config_auto_rotate = $this->config()->get('auto_rotate');
        $this->config_force_resampling = $this->config()->get('force_resampling');

        $extension = $file->getExtension();

        if ($this->config_force_resampling ||
            ($this->config_max_height && $file->getHeight() > $this->config_max_height) ||
            ($this->config_max_width && $file->getWidth() > $this->config_max_width) ||
            ($this->config_auto_rotate && preg_match('/jpe?g/i', $file->getExtension()))
        ) {
            $this->scaleUploadedImage($file);
        }
    }
1017838
public static function get_image_size( $size ) {
		// Check for a directly passed image configuration array.
		if ( is_array( $size ) ) {
			return $size;
		}

		$sizes = self::get_image_sizes();

		// Return found image size.
		if ( isset( $sizes[ $size ] ) ) {
			return $sizes[ $size ];
		}

		self::notice( "Image size \"{$size}\" does not exist in your image configuration." );

		return false;
	}
301651
public static function getSize( $size )
    {
        $dim = [];
        if( is_array( $size ) )
        {
            $dim[ 'w' ] = $size[0];
            $dim[ 'h' ] = isset( $size[1] ) ? $size[1] : $size[0];
        }
        else
        {
            $dim[ 'w' ] = $size;
            $dim[ 'h' ] = null;
        }

        return $dim;
    }
926589
public function fitHeight(&$source, $target, array $action)
    {
        $height = reset($action['value']);

        if ($this->image->set($source)->fitToHeight($height)->save($target)) {
            $source = $target;
            return true;
        }

        return false;
    }
446776
public static function getCalculatedSize($width, $height, $maxWidth, $maxHeight)
    {
        $widthDiffRatio = $maxWidth / $width;
        $heightDiffRatio = $maxHeight / $height;

        if ($widthDiffRatio <= $heightDiffRatio) {
            // resize based on width
            $newWidth = $maxWidth;
            $newHeight = $height * $widthDiffRatio;
        } else {
            // resize based on height
            $newWidth = $width * $heightDiffRatio;
            $newHeight = $maxHeight;
        }

        return [
            $newWidth,
            $newHeight,
        ];
    }
206791
protected function setFileSize($file)
    {
        $this->fileSize = ! is_null($this->elfinderFilePath) ? $this->getFileSize() : (is_string($file) ? $this->size($file) : $file->getClientSize());
    }
118168
public static function getImageSize( string $size = 'thumbnail') {
		$sizes = self::getImageSizes();
		$size  = key_exists( $size, $sizes ) ? $size : 'thumbnail';

		return $sizes[ $size ];
	}
115316
public function export($file = null)
    {
        if ($file) {
            return isset($this->_coverage[$file]) ? $this->_coverage($file, $this->_coverage[$file]) : [];
        }
        $result = [];
        $base = preg_quote($this->base(), '~');
        foreach ($this->_coverage as $file => $rawCoverage) {
            if ($coverage = $this->_coverage($file, $rawCoverage)) {
                $result[preg_replace("~^{$base}~", '', $file)] = $coverage;
            }
        }
        return $result;
    }
951041
private function getImageHeight(Image $image, int $width): int
    {
        return (int)($width * ($image->getHeight() / $image->getWidth()));
    }
1253707
public function getFile( $fileName, $target = "" )
	{
		$this->connection->checkConnection();
		if( !$target )
			$target	= $fileName;
		return @ftp_get( $this->connection->getResource(), $target, $fileName, $this->connection->mode );
	}
156093
public function setFile(File $file = null)
    {
        $this->file = $file;

        if (!empty($file)) {
            $size = @getimagesize($file->getPathname());

            if (is_array($size)) {
                list($this->width, $this->height) = $size;
            }

            $this->refreshUpdatedAt();
        }

        return $this;
    }
1036102
public function resize($width, $height)
    {
        $this->mode = 'resize';
        $this->targetSize = [$width, $height];
        $this->arguments = [];

        return $this->process();
    }
566751
public function loadImage(string $file, string $path = '') : AbstractResize
    {
        if (file_exists($path . $file) === true) {
            $this->source['path'] = $path;
            $this->source['file'] = $file;
            $this->sourceProperties();
        } else {
            throw new \Exception("File couldn't be found in supplied destination: '" . $path . $file . "'");
        }

        // Reset the processed status when a new image is loaded
        $this->processed = false;
        $this->file = null;
        $this->path = null;

        return $this;
    }
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()
            );

        }
    }
1034889
public function transform(File $file, $self = false) {
        $config = $this->getConfig();
        $baseWidth = $file->width();
        $baseHeight = $file->height();
        $width = $config['width'];
        $height = $config['height'];
        $newWidth = null;
        $newHeight = null;

        if (!is_numeric($height) && !is_numeric($width)) {
            throw new InvalidArgumentException('Invalid width and height for resize');

        } else if (empty($config['fill'])) {
            throw new InvalidArgumentException('Invalid RGB fill color');
        }

        $newWidth = $baseWidth;
        $newHeight = $baseHeight;

        // Calculate aspect ratio
        $widthAspect = $baseWidth / $width;
        $heightAspect = $baseHeight / $height;
        $aspect = ($heightAspect > $widthAspect) ? $heightAspect : $widthAspect;

        // Resize if larger image
        // @version 1.4.5 Changed to not expand the image larger than its dimensions
        if ($newWidth > $width || $newHeight > $height) {
            $newWidth = $baseWidth / $aspect;
            $newHeight = $baseHeight / $aspect;
        }

        // Determine the alignment
        $vertGap = ($height - $newHeight) / 2;
        $horiGap = ($width - $newWidth) / 2;

        if ($newWidth < $width) {
            if ($config['horizontal'] === self::LEFT) {
                $horiGap = 0;
            } else if ($config['horizontal'] === self::RIGHT) {
                $horiGap = ($width - $newWidth);
            }
        }

        if ($newHeight < $height) {
            if ($config['vertical'] === self::TOP) {
                $vertGap = 0;
            } else if ($config['vertical'] === self::BOTTOM) {
                $vertGap = ($height - $newHeight);
            }
        }

        return $this->_process($file, array(
            'width'         => $width,
            'height'        => $height,
            'dest_x'        => $horiGap,
            'dest_y'        => $vertGap,
            'dest_w'        => $newWidth,
            'dest_h'        => $newHeight,
            'quality'       => $config['quality'],
            'overwrite'     => $self,
            'preCallback'   => array($this, 'fill')
        ));
    }
1015164
public static function resizeImage($file, $width, $height, $desFile = '')
    {
        try {
            if (is_file($file)) {
                if (!$desFile) {
                    $desFile = $file;
                }
                Image::open($file)->resize($width, $height)->save($desFile);
                return true;
            }
        } catch (Exception $e) {
        }
        return false;
    }