msztorc/image-processor 问题修复 & 功能扩展

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

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

msztorc/image-processor

Composer 安装命令:

composer require msztorc/image-processor

包简介

ImageProcessor is a wrapper class for graphics libraries like GD2, ImageMagick and epeg.

README 文档

README

Build Status License

ImageProcessor Class

ImageProcessor is a wrapper class for graphics libraries like GD2, ImageMagick and epeg. Implements often used methods of graphics manipulation.

Requirements

  • GD2 (php extension)
  • ImageMagick (PECL library)
  • epeg (cli)

Library support for object

  • GD2
  • ImageMagick (PECL library)

Library support for static methods

  • ImageMagick (some functionality like resize, crop, effects)
  • epeg (cli, only for epeg_resize method)

Usage Instructions

Objected

$obj = new ImageProcessor('imagick', 'file.jpg'); // or 'gd' (default)
$obj->resize(100, 50, true, false); //width, height, aspect_ratio, enlarge
$obj->clear(); //free memory

Staticly image resize using ImageMagick (PECL extension)

ImageProcessor::imagick_resize('input-file.jpg', 'output-file.jpg', 800, 800); //infile, outfile, width, height, quality = 100, aspect_ratio = true, filter = imagick::FILTER_LANCZOS

Staticly image resize using epeg (cli)

ImageProcessor::epeg_resize('input-file.jpg', 'output-file.jpg', 800, 800); //infile, outfile, width, height, quality = 100, aspect_ratio = true

Load file

$obj = new ImageProcessor('imagick', 'infile.jpg');
// or
$obj2 = new ImageProcessor('gd', 'infile.jpg');

// clean constructor
$obj3 = new ImageProcessor(); //gd is default argument in constructor
$obj3->open('infile.jpg'); //open image

Base methods

Grayscale

$obj->grayscale();

Negative

$obj->negative();

Brightness

$obj->brightness($threshold); // +/- 100

Colorize

$obj->colorize(80,90,60); //rgb

Sepia

$obj->sepia();

Custom Sepia

$obj->grayscale();
$obj->colorize(90,60,40);

Display image

$obj->display();

Save image

$obj->save('outfile.jpg', 99); //filename, JPEG quality

You can also work on image resource

$obj->image()->resizeImage(1200,1200, imagick::FILTER_LANCZOS, 1, true); //resize using Imagick object; object must be init with second argument 'imagick'
$obj = new ImageProcessor();
$obj->open_image('imagick', $file);
//$obj->image()->setOption('jpeg:size', '300x300'); //uncomment this if you want increase speed of resize
$obj->image()->resizeImage(300,300, imagick::FILTER_LANCZOS, 1, true);

$obj->save($outfile, 75);
$obj->display();

Resize Performance

ImageMagick

JPEG image resize time from 5906x5906 to 1181x1181.

FILTER_POINT: 0.334532976151 sec
FILTER_BOX: 0.777871131897 sec
FILTER_TRIANGLE: 1.3695909977 sec
FILTER_HERMITE: 1.35866093636 sec
FILTER_HANNING: 4.88722896576 sec
FILTER_HAMMING: 4.88665103912 sec
FILTER_BLACKMAN: 4.89026689529 sec
FILTER_GAUSSIAN: 1.93553304672 sec
FILTER_QUADRATIC: 1.93322920799 sec
FILTER_CUBIC: 2.58396601677 sec
FILTER_CATROM: 2.58508896828 sec
FILTER_MITCHELL: 2.58368492126 sec
FILTER_LANCZOS: 3.74232912064 sec
FILTER_BESSEL: 4.03305602074 sec
FILTER_SINC: 4.90098690987 sec

CATROM has a very similar result to LANCZOS, but is significantly faster. ! Note! Above results are only demonstrative. Execution time depends upon the system configuration (processor speed, size of memory, etc...)

You can significantly speed up the processing bigger files using Imagick extension class by setting up jpeg:size option before open file:

$image = new Imagick();
$image->setOption('jpeg:size', '500x500');
$image->readImage('file.jpg');

or using ImageProcessor class

//$time_start = microtime(true);

$obj = new ImageProcessor('imagick');
$obj->image()->setOption('jpeg:size', '300x300');
$obj->open($file);

$obj->image()->resizeImage(300,300, imagick::FILTER_LANCZOS, 1, true);

$obj->save($outfile, 99);

//$time_end = microtime(true);
//$time = $time_end - $time_start;
//echo $time ."\n\n";

Links

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固