定制 rutkoski/simplify-thumb 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rutkoski/simplify-thumb

Composer 安装命令:

composer require rutkoski/simplify-thumb

包简介

Thumbnail generation and image processing, extendable and with a fluent interface.

README 文档

README

Thumbnail generation and image processing, extendable and with a fluent interface.

Usage:

Basic example:

$thumb = new \Simplify\Thumb();

$filename = $thumb
    ->setBaseDir(dirname(__file__))
    ->setFilesPath('files/')
    ->setCachePath('files/cache/')
    ->load('dummy.jpg')
    ->resize(150, 150)
    ->cache()
    ->getCacheFilename();

The library uses the method's parameters (like resize/150/150) to check for an existing cache file and uses it instead of recreating the image.

Output

Get the cached filename

$thumb->getCacheFilename();

or save it to a new location

$thumb->save('path/newfile.php');

or overwrite current image

$thumb->save();

or send the image to the browser

$thumb->output();

Change formats

Just use the PHP constants (IMAGETYPE_PNG, IMAGETYPE_JPEG, ...):

$thumb->cache(IMAGETYPE_PNG);

or

$thumb->output(IMAGETYPE_PNG);

Available methods

Resize

$thumb->resize($width, $height, $mode, $far, $r, $g, $b, $a);

The third parameter in resize changes how images are resized. It defaults to Simplify_Thumb::FIT\_INSIDE. Options for $mode are:

  • Simplify_Thumb::FIT_INSIDE - resize the image to fit inside a box defined by $width and $height
  • Simplify_Thumb::FIT_OUTSIDE - resize the image to fit outside a box defined by $width and $height
  • Simplify_Thumb::SCALE_TO_FIT - resize the image to exactly $width and $height
  • Simplify_Thumb::NO_SCALE - don't resize the image, that's usefull for enlarging the image canvas

The fourth parameters, $far (force aspect ratio), when true, forces the final image to be exactly $width by $height pixels. The $r, $g, $b and $a parameters set the color for the background, so, for example:

$thumb->resize(150, 150, Simplify_Thumb::FIT_INSIDE, true, 0, 0, 0, 0);

on a 300 x 100px image, would fit the image inside a 150 x 150px box with a black background.

ZoomCrop

Crops the image so that it fills the dimensions you specify. The third parameter specifies wich part of the image will be used.

$thumb->zoomCrop($width, $height, Simplify_Thumb::CENTER);

PHP image filters

$thumb->brightness($level);
$thumb->grayscale();
$thumb->negate();
$thumb->contrast($level);
$thumb->colorize($red, $green, $blue, $alpha);
$thumb->edgedetect();
$thumb->emboss();
$thumb->gaussianBlur();
$thumb->selectiveBlur();
$thumb->meanRemoval();
$thumb->smooth($level);
$thumb->pixelate($blockSize, $advanced);

Offset

Shrink/enlarge the image canvas and fill background with color.

$thumb->offset($top, $right, $bottom, $left, $r = 0, $g = 0, $b = 0, $a = 0);

$top, $right, $bottom and left are relative. Positive numbers make the canvas bigger, negative numbers make it smaller (crops the image).

Custom plugins

Implement custom plugins by extending Simplify_Thumb_Plugin and calling:

$thumb->plugin($plugin);

where $plugin is the string representing the plugin class.

Example:

Plugin that overlays an image on top of the current one:

class \Simplify\Thumb\Plugin\Overlay extends \Simplify\Thumb\Plugin
{

    protected function process(\Simplify\Thumb\Processor $thumb, $overlayImage = null)
    {
    	$overlay = \Simplify\Thumb\Functions::load($overlayImage);

    	$w = imagesx($overlay);
    	$h = imagesy($overlay);

    	imagecopyresampled($thumb->image, $overlay, 0, 0, 0, 0, $w, $h, $w, $h);
    }

}

then:

$thumb->plugin('\Simplify\Thumb\Plugin\Overlay', 'overlay.png');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL
  • 更新时间: 2013-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固