zepekegno/resize-image

调整图片大小并将其转换为另一种格式。驱动器使用GD

1.0 2022-12-11 13:23 UTC

This package is auto-updated.

Last update: 2024-09-11 19:20:30 UTC


README

example branch parameter Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

这个库可以帮助您轻松地将图片转换为其他格式。此库使用GD驱动器。支持的PHP版本:*8 我们可以用这个库做什么?

  • 我们可以将图片转换为其他格式。
  • 我们可以将图片调整大小到其他格式。
  • 我们可以同时转换和调整图片大小到其他格式。

支持调整大小的格式:PNG, JPEG, JPG, GIF 支持转换的格式:PNG, JPEG, JPG

//Resize an image

// Example with png
$source = 'image.png';

$resizeImage = new zepekegno\Resize($source,50,50);


/**
 * If file exist a copy of this file will be created with suffix cpr
*/
$resizeImage->make(target:'tmp/final',quality:9);

//if delete is true will delete this file and create a new file
$resizeImage->make(target:'tmp/final',quality:9,delete:true);

// Example with Gif

$source = 'image.gif';

$resizeImage = new zepekegno\Resize($source,50,50);

/**
 * If file exist a copy of this file will be created with suffix cpr
*/
$resizeImage->make('tmp/final');

//if delete is true will delete this file and create a new file
$resizeImage->make(target:'tmp/final',delete:true);

//Convert an image to other format 
/**
 * convert image png to jpeg
 * Return the path of image
*/
$source = 'image.png';
$convertImage = new zepekegno\Resize(source:$source,height:50,width:50);
$convertImage->convert(type:'jpeg',target:'tmp/final',quality:100,isResizable:false);

/**
 * Convert png to jpeg and resize it
 * if we want to resize, past isResizable to true
 * Return the path of image
*/
$source = 'image.png';
$convertImage = new zepekegno\Resize(source:$source,height:50,width:50);
$img = $convertImage->convert(type:'jpeg',target:'tmp/final',quality:100,isResizable:true);

// Generate image
$image = "<img src=\"{$img}\"/>";

ResizeImage使用以下参数构建

  • $source 字符串,文件名

  • $width 整数,文件的新宽度

  • $height 整数,文件的新高度

需要以下参数的make方法

  • $target 字符串,文件将存储的目录

  • $quality 整数,将用于png [0-9],jpeg或png [0-100],gif不需要使用到的图像质量

  • $delete *布尔值,可选,如果存在则删除文件,否则将复制到以*cpr为前缀的新文件中

需要以下参数的convert方法

  • $type 字符串,要转换的格式

  • $target 字符串,文件将存储的目录

  • $quality 整数,将用于png [0-9],jpeg或png [0-100],gif不需要使用到的图像质量

  • $isResizable 布尔值,可选,如果为true则转换和调整图片大小,如果为false则仅转换图片

对于Gif的转换不支持