delboy1978uk / image
PHP image class
Installs: 3 329
Dependents: 6
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^8.2
- ext-gd: *
Requires (Dev)
README
A PHP image class utilising the gd
library
Installing
composer require delboy1978uk/image
Usage
Instantiation
You can pass a path name into the constructor, or you can use the load()
method. Accepts png
, jpg
, gif
, and webp
images.
<?php use Del\Image; $image = new Image('/path/to/my.jpg'); // Or... $image = new Image(); $image->load('/path/to/my.png');
Available Methods
<?php use Del\Image; $image = new Image('/path/to/my.jpg'); $image->crop($width, $height, 'center'); // Crops the image, also accepts left or right as 3rd arg $image->destroy(); // remove loaded image in the class. Frees up any memory $image->getHeader(); // returns image/jpeg or equivalent $image->getHeight(); // returns height in pixels $image->getWidth(); // returns width in pixels $image->output(); // output to browser $image->output(true); // passing true returns raw image data string $image->outputBase64Src(); // for use here <img src="HERE" /> $image->resize($width, $height); // resize to the given dimensions $image->resizeAndCrop($width, $height); // resize to the given dimensions, cropping top/bottom or sides $image->save(); // Save the image $image->save('/path/to/save.jpg', $permissions, $compression); // Save as a different image $image->scale(50); // Scale image to a percentage