lexinzector/picture

图像处理库(裁剪和缩小,转换为base64等)

1.0 2023-10-17 07:41 UTC

This package is auto-updated.

Last update: 2024-09-17 10:14:12 UTC


README

图像处理库(裁剪和缩小,转换为base64等)

可能性

  • 按比例减少图像的宽或高
  • 按百分比减少图像大小
  • 将图像适入到一定大小的框架中
  • 任意调整图像大小
  • 更改图像质量
  • 输出生成的图像而不保存
  • 在服务器上保存图像
  • 为图像分配访问权限

需求

PHP >= 5.6.0

安装

在控制台运行

composer require lexinzector/picture

示例

use \Lexinzector\Picture\Picture;

// resize the image proportionally and save it on the server without changing the file extension
// the resulting image will not exceed 400 pixels in height and 300 in width
// that is, it will automatically fit into the required dimensions
$new_image = new Picture('url or path to file');
$new_image->autoimageresize(300, 400);
$new_image->imagesave($new_image->image_type, 'folder on the server');
$new_image->imageout();

// output to the screen without changing the file extension
$new_image = new Picture('url or path to file');
$new_image->autoimageresize(300, 400);
$new_image->imagesave($new_image->image_type, null);
$new_image->imageout();

// save on the server and select the output file type
$new_image = new Picture('url or path to file');
$new_image->autoimageresize(300, 400);
$new_image->imagesave('png', 'folder on the server');
$new_image->imageout();

// compress the file and display it on the screen
$new_image = new Picture('url or path to file');
$new_image->autoimageresize(300, 400);
$new_image->imagesave('jpeg', null, 75);
$new_image->imageout();

// save on the server, compress and set access rights
$new_image = new Picture('url or path to file');
$new_image->autoimageresize(300, 400);
$new_image->imagesave('jpeg', 'folder on the server', 75, 0777);
$new_image->imageout();

// reduce the image width
$new_image = new Picture('url or path to file');
$new_image->imageresizewidth(300);
$new_image->imagesave($new_image->image_type, 'folder on the server');
$new_image->imageout();

// reduce the image height
$new_image = new Picture('url or path to file');
$new_image->imageresizeheight(400);
$new_image->imagesave($new_image->image_type, 'folder on the server');
$new_image->imageout();

// arbitrarily reduce the image without maintaining the proportions
$new_image = new Picture('url or path to file');
$new_image->imageresize(300, 400);
$new_image->imagesave($new_image->image_type, 'folder on the server');
$new_image->imageout();

// reduce the image by percentage
$new_image = new Picture('url or path to file');
$new_image->percentimagereduce(30);
$new_image->imagesave($new_image->image_type, 'folder on the server');
$new_image->imageout();

// reduce the image without maintaining the proportions without saving the image on disk for output in base64 format
$new_image = new Picture('url or path to file');
$new_image->imageresize(300, 400);
$new_image->imagesave($new_image->image_type, 'out');
$new_image->imageout();
$dataUri = "data:image/jpeg;base64,".base64_encode($new_image->image_contents);