tomkyle / yaphr
此软件包最新版本(1.1.8)没有可用的许可信息。
1.1.8
2015-04-14 10:00 UTC
Requires (Dev)
- phpunit/phpunit: ~4.2
- satooshi/php-coveralls: dev-master
Suggests
- slim/slim: Yaphr comes with Slim Middleware for common resizing use cases.
README
#tomkyle\yaphr
针对 JPG、PNG、GIF 的另一种照片缩放器。
缩放和裁剪,清晰且实用的锐化。
##安装
Yaphr 目前没有依赖项,尽管安装 Slim 可能很有用:Yaphr 为最常见的缩放用例带来了自己的 Slim 中间件。通过 Composer 安装;将此添加到 composer.json
"require": {
"tomkyle/yaphr": "~1.1"
}
##入门
Yaphr 提供了方便的工作流程,为你完成大部分工作
use \tomkyle\yaphr\ImageFactory; use \tomkyle\yaphr\Geometry\BoxFactory; use \tomkyle\yaphr\Workflow; use \SplFileInfo; // YAPHR likes `SplFileInfo` $source = new SplFileInfo( '../master/path/to/original.jpg' ); $output = new SplFileInfo( './path/to/resized.jpg' ); // Generate factories: $image_factory = new ImageFactory; $box_factory = new BoxFactory; // Grab your instances: $image = $image_factory->newInstance( $source ); $box = $box_factory->newInstance( 300, 200, $image, 'crop'); // Convenience, convenience: // Resize, Sharpen, Save to cache // and Delivery to client in one step: new Workflow( $image, $box, $output);
所以 Workflow
是你的朋友。此示例展示了内部发生的情况
use \tomkyle\yaphr\Resize; use \tomkyle\yaphr\Filters\SharpenImage; use \tomkyle\yaphr\FileSystem\CreateCacheDir; use \tomkyle\yaphr\FileSystem\SaveImage; use \tomkyle\yaphr\FileSystem\DeliverImage; // Create resized (cropped) image: $resized = new Resize($image, $box); // Make it nice and crisp: new SharpenImage( $resized ); // Save to file cache: new CreateCacheDir( $output, 0775 ); new SaveImage( $resized, $output, 85 ); // Send to client: new DeliverImage( $output, "exit" );
##缩放框 Yaphr 提供了各种缩放模式,它们在不同用例中都很有用。如果你确切知道你想要什么,你可以实例化一个具体的 Box 类;使用带有字符串参数的 BoxFactory
提供了更多的灵活性:只需传递所需的 $width
和 $height
、原始的 $image
和框类型。
裁剪 从原始图像中提取尽可能多的内容,使其适合给定的宽度和高度。对于具有不同边比的图片最有用,例如在响应式环境中。
$exact = new CropBox( $width, $height, $image ); // same as $exact = $box_factory->newInstance( $width, $height, $image, 'crop');
自动 使肖像图像高度为 $height
像素,风景图像高度为 $width
像素,同时保留边比。也许是最经典的缩放模式。
$exact = new AutoBox( $width, $height, $image ); // same as $exact = $box_factory->newInstance( $width, $height, $image, 'auto');
精确 将图像适应用于给定的宽度和高度,不保留边比(即结果可能会失真)。除了失真之外,通常没有用(好吧,失真)。
$exact = new Box( $width, $height ); // same as $exact = $box_factory->newInstance( $width, $height, $image, 'exact');
高 无论如何都缩放为给定的高度,但保留边比。对于水平“相同高度”画廊或 砌体画廊 非常有用。
$exact = new TallBox( $height, $image ); // same as $exact = $box_factory->newInstance( $height, $height, $image, 'tall');
宽 无论如何都缩放为给定的高度,但保留边比。对于垂直“相同宽度”画廊非常有用。
$exact = new WideBox( $width, $image ); // same as $exact = $box_factory->newInstance( $width, $width, $image, 'wide');
##类概述
###图像类
# Classes use \tomkyle\yaphr\GifImage; use \tomkyle\yaphr\JpegImage; use \tomkyle\yaphr\PngImage; # Abstracts and Interfaces use \tomkyle\yaphr\ImageAbstract; use \tomkyle\yaphr\ImageInterface; use \tomkyle\yaphr\GifImageInterface; use \tomkyle\yaphr\JpegImageInterface; use \tomkyle\yaphr\PngImageInterface;
###业务类
# Classes use \tomkyle\yaphr\ImageFactory; use \tomkyle\yaphr\Workflow; use \tomkyle\yaphr\Resize;
###几何类
# Boxes use \tomkyle\yaphr\Geometry\Box; use \tomkyle\yaphr\Geometry\BoxFactory; use \tomkyle\yaphr\Geometry\AutoBox; use \tomkyle\yaphr\Geometry\CropBox; use \tomkyle\yaphr\Geometry\SquareBox; use \tomkyle\yaphr\Geometry\TallBox; use \tomkyle\yaphr\Geometry\WideBox; # Coordinates use \tomkyle\yaphr\Geometry\CropStartCoordinates; use \tomkyle\yaphr\Geometry\NullCoordinates; # Abstracts and Interfaces use \tomkyle\yaphr\Geometry\CoordinatesInterface; use \tomkyle\yaphr\Geometry\BoxAbstract; use \tomkyle\yaphr\Geometry\BoxInterface; use \tomkyle\yaphr\Geometry\CropBoxInterface;
###图像过滤器类
# Classes use \tomkyle\yaphr\Filters\SharpenImage; use \tomkyle\yaphr\Filters\UnsharpMask; # experimental
###文件系统类
# Classes use \tomkyle\yaphr\FileSystem\CreateCacheDir; use \tomkyle\yaphr\FileSystem\CheckReadableFile; use \tomkyle\yaphr\FileSystem\DeliverImage; use \tomkyle\yaphr\FileSystem\FileExtension; use \tomkyle\yaphr\FileSystem\SaveImage; use \tomkyle\yaphr\FileSystem\SaveGif; use \tomkyle\yaphr\FileSystem\SaveJpeg; use \tomkyle\yaphr\FileSystem\SavePng; # Abstracts and Interfaces use \tomkyle\yaphr\FileSystem\SaveImageAbstract; use \tomkyle\yaphr\FileSystem\SaveImageInterface;
###异常
# Classes and Interfaces use \tomkyle\yaphr\Exceptions\FileNotFound; use \tomkyle\yaphr\Exceptions\YaphrException; use \tomkyle\yaphr\Exceptions\YaphrExceptionInterface;
###PHP 资源聚合
# Interfaces and traits use \tomkyle\yaphr\Resources\ResourceAggregate; use \tomkyle\yaphr\Resources\ResourceAggregateTrait;