PHP code example of guillaumetissier / image-resizer
1. Go to this page and download the library: Download guillaumetissier/image-resizer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guillaumetissier / image-resizer example snippets
use Guillaumetissier\ImageResizer\ImageResizer;
use Guillaumetissier\ImageResizer\Constants\Transformations;
use Guillaumetissier\ImageResizer\Constants\Options;
// Create resizer with safe configuration
$resizer = ImageResizer::create();
// Resize image
$resizer
->setTransformation(Transformations::SET_RATIO, 0.8)
->setOption(Options::QUALITY, 85)
->resize('source.jpg', 'output.jpg');
use Guillaumetissier\ImageResizer\Constants\ResizeType;
use Guillaumetissier\ImageResizer\ImageResizer;
use Guillaumetissier\ImageResizer\Constants\Transformations;
$resizer = ImageResizer::create();
// Resize by aspect ratio (default)
$resizer
->setTransformation(Transformations::SET_RATIO, 2)
->resize('image.jpg', 'resized.jpg');
// Resize by width (maintains aspect ratio)
$resizer
->setResizeType(ResizeType::FIXED_WIDTH)
->setTransformation(Transformations::SET_WIDTH, 800)
->resize('image.jpg', 'resized.jpg');
// Resize by height (maintains aspect ratio)
$resizer
->setResizeType(ResizeType::FIXED_HEIGHT)
->setTransformation(Transformations::SET_HEIGHT, 600)
->resize('image.jpg', 'resized.jpg');
// Resize with fixed height and width
$resizer
->setResizeType(ResizeType::FIXED)
->setTransformation(Transformations::SET_HEIGHT, 600)
->setTransformation(Transformations::SET_WIDTH, 300)
->resize('image.jpg', 'resized.jpg');
public static function create(?ImageResizerConfig $config = null): self
// Set a single transformation
public function setTransformation(Transformations $transformation, mixed $value): self
// Set multiple transformations at once
public function setTransformations(array $transformations): self
// Set a single option
public function setOption(Options $option, int|bool|string $value): self
// Set multiple options at once
public function setOptions(array $options): self
// Resize the image
public function resize(string $source, ?string $target = null): void
public static function default(): self
public static function safe(): self
public static function strict(): self
public static function thumbnail(): self
public static function web(): self
public static function print(): self
public function __construct(array $config = [])
Transformations::SET_WIDTH // Resize by width
Transformations::SET_HEIGHT // Resize by height
Transformations::SET_RATIO // Resize by aspect ratio
// ❌ v1.x - No longer works
$resizer = new ImageResizer(...);
// ✅ v2.0 - Use factory method
$resizer = ImageResizer::create();
$resizer = ImageResizer::create(ImageResizerConfig::safe());
// This works in both v1.x and v2.0
$resizer = ImageResizer::create();
$resizer->setTransformation(Transformations::SET_WIDTH, 800);
$resizer->resize('input.jpg', 'output.jpg');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.