定制 midnight/image 二次开发

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

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

midnight/image

Composer 安装命令:

composer require midnight/image

包简介

An image editing library

README 文档

README

A small image editing library for PHP

Installation

The library is available as a Composer package:

./composer.phar require midnight/image

Usage

Open an image:

$image = \Midnight\Image\Image::open('path/to/image.jpg');

Apply a filter:

$image->fit(array('width' => 150, 'height' => 200));

Get the new image after applying a filter:

$image->getFile();

Included filters

The library comes with some pre-defined filters. They can be accessed by calling the filter name as a method of the image object. All filters accept an options array as their only argument. For example:

$options = array('foo' => true, 'bar' => 42);
$filtered_image = $image->filterName($options);

fit

Scales the image up or down to fit it inside a rectangle defined by the options width and height. It's the equivalent of CSS's background-size: contain property or Adobe InDesign's "Fit proportionally" option.

// $image has a size of 1500 by 2000 pixels
$thumbnail = $image->fit(array('width' => 200, 'height' => 200));
// $thumbnail is 150 x 200 pixels 

fill

The fill filter fills a rectangle defined by the options width and height. It's the equivalent of CSS's background-size: cover property or Adobe InDesign's "Fill proportionally" option. It will most likely crop parts of the image.

// $image has a size of 1500 by 2000 pixels
$thumbnail = $image->fill(array('width' => 200, 'height' => 200));
// $thumbnail is 200 x 200 pixels, with cropped areas at the top and bottom

brighten

Brightens the image. The only option is amount, which accepts an integer from -255 (which actually darkens the image) to 255.

$brightened = $image->brighten(array('amount' => 50));

desaturate

Desaturates the image. The only option is amount, which accepts an integer from -100 (which actually saturates image) to 100.

$desaturated = $image->desaturate(array('amount' => 25));

colorcast

Applies a color cast to the image. The available options are color, which accepts an instance of Midnight\Color\Color (actually ColorInterface) and amount, which accepts a value between 0 and 1.

// Apply a red color cast.
$red = new \Midnight\Color\Color(255, 0, 0);
$colorcasted = $image->colorcast(array('color' => $red, 'amount' => .2));

noise

Adds noise to the image. The only option available is amount.

$noisy = $image->noise(array('amount' => .1));

Adding a custom filter

You can easily add a custom filter:

class MyCustomFilter extends \Midnight\Image\Filter\AbstractGdFilter
{
    public function filter($image)
    {
        parent::filter($image);

        $cache = $this->getCache();
        if ($cache->exists($this)) {
            return Image::open($cache->getPath($this));
        }

        $im = $this->getGdImage();

        // Do stuff to GD image resource $im

        $image = $this->save($im);

        return $image;
    }
}
$plugin_manager = \Midnight\Image\ImagePluginManager::getInstance();
$plugin_manager->setService('myCustomFilter', 'MyCustomFilter');

// Use the filter
$filtered = \Midnight\Image\Image::open('file.jpg')->myCustomFilter();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固