1. Go to this page and download the library: Download coderden/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/ */
coderden / image-resizer example snippets
$processor = new ImageProcessor('gd'); // or 'imagick'
// Load, resize, and save
$processor->load('input.jpg')
->resize(800, 600)
->save('output.jpg', 85);
// Get image as string
$imageData = $processor->load('photo.png')
->crop(300, 300)
->get('webp', 80);
$processor = new ImageProcessor();
// Resize with width only (maintains aspect ratio)
$processor->load('image.jpg')
->resize(800)
->save('resized.jpg');
// Resize with height only
$processor->load('image.jpg')
->resize(null, 600)
->save('resized.jpg');
// Resize to exact dimensions (may distort)
$processor->load('image.jpg')
->resize(800, 600)
->save('resized.jpg');
// Crop to specific dimensions
$processor->load('image.jpg')
->crop(300, 200)
->save('cropped.jpg');
// Crop with custom position
$processor->load('image.jpg')
->crop(300, 200, 100, 50) // x=100, y=50
->save('cropped.jpg');
// Crop to 16:9 aspect ratio
$processor->load('image.jpg')
->aspectRatio(16/9)
->save('widescreen.jpg');
// Crop to square with top alignment
$processor->load('image.jpg')
->aspectRatio(1, 'top')
->save('square-top.jpg');
// Available positions: 'center', 'top', 'bottom', 'left', 'right'
// Use GD driver (default)
$processor = new ImageProcessor('gd');
// Use Imagick driver (= $processor->driver('imagick')
->load('image.tiff')
->resize(800, 600)
->get('jpg');
// Get as binary string
$jpegData = $processor->load('image.png')
->resize(800, 600)
->get('jpg', 85);
// Get image dimensions
$dimensions = $processor->load('image.jpg')
->getDimensions();
// Returns: ['width' => 1920, 'height' => 1080]
use CoderDen\ImageResizer\Resizer;
// Quick resize and save
Resizer::resize('input.jpg', 'output.jpg', 800, 600);
// Load and process with method chaining
Resizer::load('image.jpg')
->resize(300, 200)
->rotate(90)
->save('processed.jpg');
// Use different driver
Resizer::driver('imagick')
->load('image.tiff')
->save('output.jpg');