1. Go to this page and download the library: Download migears/image 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/ */
migears / image example snippets
use MiGears\Image\GDImage;
use MiGears\Image\ImageType;
// Load from file
$img = new GDImage('/path/to/image.jpg');
// Chain operations and save
$img->resizeToWidth(800)
->cropCenter(400, 300)
->save('/path/to/output.jpg', ImageType::JPEG, 90);
// Generate thumbnail (resize then crop, centered)
$img->thumbnail(200, 200)->save('/path/to/thumb.jpg');
// Add image watermark
$img->imageWatermark('/path/to/watermark.png', 10, 10, 70)
->save('/path/to/wm.jpg');
// Add text watermark
$img->textWatermark(
text: 'Copyright',
fontFile: '/path/to/font.ttf',
fontSize: 14,
x: 10,
y: 10,
opacity: 80,
color: 0xFFFFFF,
)->save('/path/to/text-wm.jpg');
// Format conversion
$img->save('/path/to/output.webp', ImageType::WEBP);
use MiGears\Image\GDImage;
$img = new GDImage('/path/to/photo.jpg');
// Rotate 90 degrees clockwise
$img->rotate(90)->save('/path/to/rotated.jpg');
// Rotate with custom background color (for non-90° angles)
$img->rotate(45, 0xFFFFFF)->save('/path/to/tilted.jpg');
// Flip horizontally (mirror effect)
$img->flipHorizontal()->save('/path/to/mirrored.jpg');
// Flip vertically
$img->flipVertical()->save('/path/to/flipped.jpg');
use MiGears\Image\GDImage;
use MiGears\Image\ImageType;
// Generate avatar dynamically
$img = new GDImage('/path/to/avatar.png');
$img->resizeToWidth(128);
// Set Content-Type and output
header('Content-Type: ' . ImageType::PNG->mime());
echo $img->output(ImageType::PNG);
// From file path — the type is detected from the file content
new GDImage(string $filePath);
// Passing a type for a file path is optional and may only confirm the detected type,
// otherwise ImageException is thrown
new GDImage(string $filePath, ImageType $type);
// From GD resource — there is no file to inspect, so $type is used as-is (defaults to PNG)
new GDImage(\GdImage $resource, ?ImageType $type = null);