rundiz/image 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rundiz/image

最新稳定版本:3.1.6

Composer 安装命令:

composer require rundiz/image

包简介

Image manipulation use GD or Imagick as drivers. It support watermark image or text, resize, crop, rotate, transparency gif or png and also support animation gif (Imagick only).

README 文档

README

Simple image manipulation that use GD or Imagick as drivers.

Features:

File extensions supported

  • AVIF (AVIFS)*
  • GIF
  • JPG (JPEG)
  • PNG
  • WEBP*

Functional

  • Crop
  • Flip (Require PHP 5.5+ for GD driver.)
  • Resize (aspect ratio and not)
  • Rotate
  • Watermark image (including alpha transparency.)
  • Watermark text (including alpha transparency.)
  • Supported alpha transparency or transparent AVIF, GIF, PNG, WEBP.
  • Supported animated GIF, WEBP* (Imagick only).

Latest Stable Version License Total Downloads

Tested up to PHP 8.5.

Example

Drivers

Gd driver

$Image = new \Rundiz\Image\Drivers\Gd('/path/to/source-image.jpg');

Imagick driver

$Image = new \Rundiz\Image\Drivers\Imagick('/path/to/source-image.jpg');

Fallback drivers

You can use multiple drivers as fallback if it does not support.

if (extension_loaded('imagick') === true) {
    $Image = new \Rundiz\Image\Drivers\Imagick('/path/to/source-image.jpg');
} else {
    $Image = new \Rundiz\Image\Drivers\Gd('/path/to/source-image.jpg');
}

Image manipulation methods

// Crop an image
$Image->crop(400, 400, 'center', 'middle');// crop start from center of X and Y
$Image->crop(400, 400, 20, 90);// crop start from X 20 and Y 90

// Resize
$Image->resize(600, 400);
// Resize without aspect ratio
$Image->resizeNoRatio(500, 300);

// Rotate
$Image->rotate();// 90 degree
$Image->rotate(180);
$Image->rotate(270);

// Flip
$Image->rotate('hor');// horizontal
$Image->rotate('vrt');//  vertical
$Image->rotate('horvrt');// both horizontal and vertical

// Watermark image
$Image->watermarkImage('/var/www/image/watermark.png', 'center', 'middle');
$Image->watermarkImage('/var/www/image/watermark.png', 50, 90);// watermark start from X 50 and Y 90

// Watermark text
$Image->watermarkText('hello world', '/var/www/fonts/myfont.ttf', 'center', 'middle', 16);
$Image->watermarkText('hello world', '/var/www/fonts/myfont.ttf', 50, 90, 16);// watermark start from X 50 and Y 90

Multiple image process

$Image = new \Rundiz\Image\Drivers\Gd('/path/to/source-image.jpg');
$Image->resize(900, 600);
$Image->save('/path/to/new-file-name-900x600.jpg');
// Use method clear() to clear all processed data 
// and start new image process with the same image source.
$Image->clear();
$Image->resize(300, 100);
$Image->save('/path/to/new-file-name-300x100.jpg');

For more details, please look in tests folder or see API doc

Remark:

  • *AVIF
    • PHP and Imagick that use ImageMagick prior 7.0.10-25 doesn't supported open or save AVIF.
      Some older system may be able to save but the file's mime type will not changed.
    • PHP and Imagick (depend on ImageMagick) doesn't supported animated AVIF (AVIFS).
    • PHP 8.3 and older with GD doesn't supported some kind of AVIF (reference).
    • PHP prior 8.1 with GD doesn't supported AVIF.
  • *WEBP
    • PHP and Imagick that use ImageMagick prior 7.0.8.68 doesn't supported open or save animated WEBP.
    • PHP all version (last checked 8.5) with GD doesn't supported animated WEBP.
    • PHP prior 7.0 with GD (ref. 1, 2) doesn't supported open or save transparent WEBP.
    • PHP prior 5.6 with GD doesn't fully supported WEBP and may cause image becomes green. Tested with PHP on Windows.

统计信息

  • 总下载量: 479
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-20