Imagine是一个php处理图片的库,自己项目里面用到又经常忘记一些变量名,官方文档打开还挺慢的,赶紧记下。
<?php
$imagine = new Imagine\Imagick\Imagine();
$imagine->open('/path/to/image.jpg')
->save('/path/to/image.jpg', array('jpeg_quality' => 50)) // from 0 to 100
->save('/path/to/image.png', array('png_compression_level' => 9)); // from 0 to 9
->save('/path/to/image.webp', array('webp_quality' => 50)) // from 0 to 100
<?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();
// or
$imagine = new Imagine\Imagick\Imagine();
// or
$imagine = new Imagine\Gmagick\Imagine();
$size = new Imagine\Image\Box(40, 40);
// The original image is scaled so it is fully contained within the thumbnail dimensions (the image width/height ratio doesn't change).
$mode = Imagine\Image\ImageInterface::THUMBNAIL_INSET;
// or
//The thumbnail is scaled so that its smallest side equals the length of the corresponding side in the original image (the width or the height are cropped).
$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
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.