delboy1978uk / image
PHP图像类
v2.6.1
2024-03-31 20:02 UTC
Requires
- php: ^8.2
- ext-gd: *
Requires (Dev)
README
安装
composer require delboy1978uk/image
用法
实例化
你可以将路径名传递给构造函数,或者可以使用load()
方法。支持png
、jpg
、gif
和webp
图像。
<?php use Del\Image; $image = new Image('/path/to/my.jpg'); // Or... $image = new Image(); $image->load('/path/to/my.png');
可用方法
<?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