目录
Imagine是一个php处理图片的库,自己项目里面用到又经常忘记一些变量名,官方文档打开还挺慢的,赶紧记下。
图片指定格式保存压缩
<?php
$imagine = new Imagine\Imagick\Imagine();
$imagine->open('/path/to/image.jpg')
->save('/path/to/image.jpg', array('jpeg_quality' => 50))
->save('/path/to/image.png', array('png_compression_level' => 9));
->save('/path/to/image.webp', array('webp_quality' => 50))
截图
<?php
use Imagine\Image\Box;
use Imagine\Image\Point;
$image->resize(new Box(15, 25))
->rotate(45)
->crop(new Point(0, 0), new Box(45, 45))
->save('/path/to/new/image.jpg');
缩略图
$imagine = new Imagine\Gd\Imagine();
$imagine = new Imagine\Imagick\Imagine();
$imagine = new Imagine\Gmagick\Imagine();
$size = new Imagine\Image\Box(40, 40);
$mode = Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$mode = Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
$imagine->open('/path/to/large_image.jpg')
->thumbnail($size, $mode)
->save('/path/to/thumbnail.png')
调整图像大小
<?php
use Imagine\Image\Box;
use Imagine\Image\Point;
$image->resize(new Box(15, 25))
设置交错类型
$image = $imagine->open('/path/to/image.jpg');
$image->interlace(\Imagine\Image\ImageInterface::INTERLACE_LINE)->show('png');
图像引擎和各个模式的支持情况
引擎 |
INTERLACE_NONE |
INTERLACE_LINE |
INTERLACE_PLANE |
INTERLACE_PARTITION |
GD |
Y |
Y |
N |
N |
Gmagick |
Y |
N |
N |
N |
Imagick |
Y |
Y |
Y |
Y |
模式 |
INTERLACE_NONE |
INTERLACE_LINE |
INTERLACE_PLANE |
INTERLACE_PARTITION |
描述 |
基线模式 |
线交错扫描 |
平面交错扫描 |
分区交错扫描 |
interlace type
interlace type
the type of interlacing scheme: None, Line, Plane, or Partition. The default is None.
This option is used to specify the type of interlacing scheme for raw image formats such as RGB or YUV. None means do not interlace (RGBRGBRGBRGBRGBRGB…), Line uses scanline interlacing (RRR…GGG…BBB…RRR…GGG…BBB…), and Plane uses plane interlacing (RRRRRR…GGGGGG…BBBBBB…). Partition is like plane except the different planes are saved to individual files (e.g. image.R, image.G, and image.B).
Use Line, or Plane to create an interlaced GIF or progressive JPEG image.