dev-master
9999999-devA light weight php library for cropping and resizing images.
MIT
The Requires
- ext-gd *
- php ^7.1
The Development Requires
by Sami Piirainen
Wallogit.com
2017 © Pedro Peláez
A light weight php library for cropping and resizing images.
A light weight php library for cropping and resizing images., (*1)
To install SimpleImageCropper run the following command:, (*3)
``` bash $ composer require sayme/simple-image-cropper, (*4)
### Initialize Initialize SimpleImageCropper with URL as image source. ```php use SimpleImageCropper\Cropper; $cropper = new Cropper('http://example.com/your-image.png');
Or you can use $_FILES['filename']['tmp_name'] as source., (*5)
$cropper = new Cropper($_FILE['filename']['tmp_name']);
When initializing the Cropper you will have access to some of the original image meta., (*6)
$cropper->getWidth()
$cropper->getHeight()
$cropper->getType()
Cropping the image in center and saving the new image., (*7)
$width = 150;
$height = 150;
// This will crop the image in center with the new width and height
$cropper->crop($width, $height);
// This will save your new image as mynewimage.png in the current directory
$cropper->save('mynewimage.png');
// You can also set the quality of the image to be saved in the second parameter.
// The quality is by default 75, you can set it to a quality between 0-100
$cropper->save('mynewumage.png', 50);
You can also output the image as BLOB for saving it in your database or just outputting it directly., (*8)
echo $cropper->getData();
You can also set the background color of pngs (RGB), (*9)
// set the color
$color = [
'r' => 150,
'g' => 150,
'b' => 150
];
$cropper->crop($width, $height, $color['r'], $color['g'], $color['b']);
use SimpleImageCropper\Cropper;
$cropper = new Cropper('http://example.com/your-image.png');
// Crop the image by 200x200
$cropper->crop(200, 200);
// Save the image as mynewimage.png
$cropper->save('mynewimage.png');
// Set header
header('Content-Type: image/png');
use SimpleImageCropper\Cropper;
$cropper = new Cropper('http://example.com/your-image.png');
// Crop the image by 200x200 and output it.
echo $cropper->crop(200, 200)->getData();
$cropper = new Cropper($_FILES['filename']['tmp_name']);
// Set the new width
$newWidth = 306;
// Check proportions
$proportion = $newWidth / $img->width;
// Set the new height
$newHeight = $img->height * $proportion;
// Crop the image by its new width and height
$cropper->crop($newWidth, $newHeight);
// Save the image with a 50% quality
$cropper->save('mynewimage.png', 50);
A light weight php library for cropping and resizing images.
MIT