wapmorgan/image-editor

此包已被弃用且不再维护。作者建议使用wapmorgan/imagery包代替。

简单的图像编辑器,用于调整图像大小、裁剪以及其他基本图像操作。

v0.0.7 2017-01-11 17:19 UTC

This package is auto-updated.

Last update: 2019-02-20 19:59:41 UTC


README

!! 已迁移到另一个仓库:https://github.com/wapmorgan/Imagery 此仓库无法更新!

ImageEditor 是 gd 函数的包装器。之前它只在 yii-application 上下文中工作,现在您可以在任何应用程序中使用此包。

Composer package Latest Stable Version Total Downloads License

安装

  • Composer 包:wapmorgan/image-editor [1]
  • 存档:https://github.com/wapmorgan/ImageEditor/archive/master.zip

如何开始:从现有文件创建或创建一个空区域

$image = ImageEditor::createFromFile($filename);
// or
$image = ImageEditor::createWithSize($width, $height);
// or
$image = ImageEditor::createFromResource(imagecreatetruecolor(90, 90));

属性

  1. width - 图像宽度
  2. height - 图像高度
  3. resource - 图像的原始 gd-resource(您可以将其直接传递给 image-gd 函数)

操作

调整大小 && 缩放(不裁剪图像)

可以最小化和最大化图像:

  1. zoomWidthTo(int $size) - 按比例更改图像宽度为 $size
  2. zoomHeightTo(int $size) - 按比例更改图像高度为 $size

只能最小化图像:

  1. decreaseWidthTo(int $size) - 按比例减小图像宽度到 $size,如果需要的话
  2. decreaseHeightTo(int $size) - 按比例减小图像高度到 $size,如果需要的话
  3. decreaseTo(int $size) - 按比例减小较大的边到 $size,如果需要的话

可以完成您要求的所有操作:

  1. resize(int $width, int $height) - 将图像调整大小为 $width X $height

裁剪(可以裁剪图像)

  1. crop($x, $y, $x2, $y2) - 裁剪图像的一个矩形部分
  2. decreaseSide($side, int $size) - 从特定边删除图像的一部分。例如,如果 $side=top 且 $size=100,则顶部将删除 100px。

旋转 && 镜像

  1. rotate($angle, $bgColor = 0) - 旋转图像。 True 等于 90°,False 等于 -90°。
  2. horizontalFlip() - 水平翻转图像。
  3. verticalFlip() - 垂直翻转图像。

处理

  1. appendImageTo($side, ImageEditor $appendix, int $modifiers) - 将图像($appendix)附加到当前图像的 $side(《top|bottom|left|right》)
  2. placeImageAt($x, $y, ImageEditor $image) - 在 $x X $y 处将图像放置在当前图像之上。
  3. placeImageAtCenter(ImageEditor $image) - 将图像放置在当前图像的中心。

保存

  1. save($filename, $format, $quality) - 将图像保存到磁盘。可能的 $format 值:jpeg、png、gif、wbmp。质量是一个介于 0(最差)和 100(最佳)之间的整数。

链接

变更日志

+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| version                                        | date         | description                                                                                                            |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.6: composer fixes and ImageEditor updates | May 19, 2014 | Changed:                                                                                                               |
|                                                |              | * Method **saveToFile()** marked as depricated. Now use **save()** method instead.                                     |
|                                                |              | * Added method **tryCreateFromFile()** which returns either an ImageEditor instance (on success) or null (on failure). |
|                                                |              | * Fixed composer configuration (autoloading and requirements).                                                         |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.5: instantiation from bmp files           | May 6, 2014  | Changed:                                                                                                               |
|                                                |              | * Added function **imagecreatefrombmp**.                                                                               |
|                                                |              | * Some updates in `saveToFile()`: now you can use predefined constants like IMAGETYPE_XXX to specify output format.    |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.4: new class ImageEditorTools             | Apr 22, 2014 | Changed:                                                                                                               |
|                                                |              | * Added **ImageEditorTools.php** with `pHash()` method.                                                                |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.3: standalone using and composer.json     | Apr 22, 2014 | Changed:                                                                                                               |
|                                                |              | * Added **CComponent.php**. **ImageEditor** loads in automatically if need. (so you can use ImageEditor without yii).  |
|                                                |              | * Added **composer.json**. Packagist name: `wapmorgan/image-editor`                                                    |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.2: a lot of changes                       | Apr 12, 2014 | Changed:                                                                                                               |
|                                                |              | * allowing clone object.                                                                                               |
|                                                |              | * returning $this in all methods.                                                                                      |
|                                                |              | * **cropSide** renamed to **decreaseSide**.                                                                            |
|                                                |              | * added **decreaseWidthTo**(), **decreaseHeightTo**() and **decreaseTo**().                                            |
|                                                |              | * **appendImageTo**() finished.                                                                                        |
|                                                |              | * **rotate()** fixed.                                                                                                  |
|                                                |              | * **added gif and wbmp** formats in saveToFile().                                                                      |
|                                                |              | * **added mirroring functions**: horizontalFlip() and verticalFlip().                                                  |
|                                                |              | * **added createFromResource** static public method.                                                                   |
|                                                |              | * **created testing script**, **added docs**.                                                                          |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| first commit                                   | Oct 4, 2013  |                                                                                                                        |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+