src/includes/classes/Core/Utils/Image.php
public function resize(array $args): bool
    {
        if (!class_exists('Imagick')) {
            return false;
        }
        $default_args = [
            'file'   => '',
            'format' => '',

            'size'   => 0,
            'width'  => 0,
            'height' => 0,
            'crop'   => '',

            'filter'  => \Imagick::FILTER_LANCZOS,
            'blur'    => 1,
            'bestfit' => false,

            'output_file'   => '',
            'output_format' => '',
        ];
        $args += $default_args; // Defaults.
        $args = $this->parseFormatArgs($args);

        if (!is_file($args['file']) || !$args['format']) {
            return false; // Not possible.
        } elseif (!$args['output_file'] || !$args['output_format']) {
            return false; // Not possible.
        }
        $args['size']   = max(0, (int) $args['size']);
        $args['width']  = max(1, (int) ($args['width'] ?: $args['size']));
        $args['height'] = max(1, (int) ($args['height'] ?: $args['size']));
        $args['crop']   = mb_strtolower((string) $args['crop']);

        $args['filter']  = (int) $args['filter'];
        $args['blur']    = (int) $args['blur'];
        $args['bestfit'] = (bool) $args['bestfit'];

        $output_file_existed_prior = is_file($args['output_file']);

        try { // Catch exceptions.
            $image = new \Imagick();
            $image->setBackgroundColor('transparent');
            $image->readImage($args['format'].':'.$args['file']);

            if ($args['crop'] === 'thumbnail') {
                $image->cropThumbnailImage($args['width'], $args['height']);
                //
            } elseif ($args['format'] === 'svg') {
                $svg   = $image;
                $image = new \Imagick();

                $res_x = ceil(300 * ($args['width'] / $svg->getImageWidth()));
                $res_y = ceil(300 * ($args['height'] / $svg->getImageHeight()));
                $image->setResolution($res_x, $res_y); // Before filling.

                $image->setBackgroundColor('transparent');
                $image->readImage($args['format'].':'.$args['file']);
                $image->scaleImage($args['width'], $args['height'], $args['bestfit']);
            } else {
                $image->resizeImage($args['width'], $args['height'], $args['filter'], $args['blur'], $args['bestfit']);
            }
            $image->writeImage($args['output_format'].':'.$args['output_file']);

            return true; // Success.
            //
        } catch (\Throwable $Exception) {
            echo $Exception->getMessage()."\n";
            if (!$output_file_existed_prior && is_file($args['output_file'])) {
                unlink($args['output_file']);
            }
            return false;
        }
    }
public function resize(array $args): bool
    {
        if (!class_exists('Imagick')) {
            return false;
        }
        $default_args = [
            'file'   => '',
            'format' => '',

            'size'   => 0,
            'width'  => 0,
            'height' => 0,
            'crop'   => '',

            'filter'  => \Imagick::FILTER_LANCZOS,
            'blur'    => 1,
            'bestfit' => false,

            'output_file'   => '',
            'output_format' => '',
        ];
        $args += $default_args; // Defaults.
        $args = $this->parseFormatArgs($args);

        if (!is_file($args['file']) || !$args['format']) {
            return false; // Not possible.
        } elseif (!$args['output_file'] || !$args['output_format']) {
            return false; // Not possible.
        }
        $args['size']   = max(0, (int) $args['size']);
        $args['width']  = max(1, (int) ($args['width'] ?: $args['size']));
        $args['height'] = max(1, (int) ($args['height'] ?: $args['size']));
        $args['crop']   = mb_strtolower((string) $args['crop']);

        $args['filter']  = (int) $args['filter'];
        $args['blur']    = (int) $args['blur'];
        $args['bestfit'] = (bool) $args['bestfit'];

        $output_file_existed_prior = is_file($args['output_file']);

        try { // Catch exceptions.
            $image = new \Imagick();
            $image->setBackgroundColor('transparent');
            $image->readImage($args['format'].':'.$args['file']);

            if ($args['crop'] === 'thumbnail') {
                $image->cropThumbnailImage($args['width'], $args['height']);
                //
            } elseif ($args['format'] === 'svg') {
                $svg   = $image;
                $image = new \Imagick();

                $res_x = ceil(300 * ($args['width'] / $svg->getImageWidth()));
                $res_y = ceil(300 * ($args['height'] / $svg->getImageHeight()));
                $image->setResolution($res_x, $res_y); // Before filling.

                $image->setBackgroundColor('transparent');
                $image->readImage($args['format'].':'.$args['file']);
                $image->scaleImage($args['width'], $args['height'], $args['bestfit']);
            } else {
                $image->resizeImage($args['width'], $args['height'], $args['filter'], $args['blur'], $args['bestfit']);
            }
            $image->writeImage($args['output_format'].':'.$args['output_file']);

            return true; // Success.
            //
        } catch (\Throwable $Exception) {
            echo $Exception->getMessage()."\n";
            if (!$output_file_existed_prior && is_file($args['output_file'])) {
                unlink($args['output_file']);
            }
            return false;
        }
    }
Resize image.

@since 17xxxx Imagick utils.

@param array $args Named arguments.

@return bool True on success.