microstudi/silex-image-controller

Silex 的 Microstudi/Image 控制器服务提供商。

v2.0.2 2017-05-02 11:10 UTC

This package is not auto-updated.

Last update: 2024-09-13 15:35:47 UTC


README

使用 Intervention/image 服务提供商为 Silex 提供自动图像缩放控制器。

Downloads Travis status License

需求

安装

使用 composer

composer require microstudi/silex-image-controller

用法

use Microstudi\Silex\ImageController\ImageController;
use Microstudi\Silex\InterventionImage\InterventionImageServiceProvider;

$app = new Silex\Application();
$app->register(new InterventionImageServiceProvider);
      ;

//Automatic images
$app->mount('/your_path', new ImageController(array(
                'image_path' => '/path/to/original/images',
                'image_cache_path' => '/path/to/cache/folder'
            ) ));

$app->run();

Twig 辅助函数:如果存在 twig,可以使用便捷函数生成自动调整大小的图像的正确 URL image_path(image, size)

{{ image_path('path/to/image.png', 100, 100) }}
{{ image_path('path/to/image.png', 100, 100, 'c') }}

URL 例子

your_path/200x300/products/image_product.jpg    <- width or height will be
                                                   changed if necessary but
                                                   never increased
your_path/200x300xc/products/image_product.jpg  <- cropped, ensures exact sizes
your_path/200x0/products/image_product.jpg      <- auto-calculate height
your_path/0x300/products/image_product.jpg      <- auto-calculate width

选项

  • intervention.image - Intervention\Image\ImageManager 的实例。
  • intervention.response - 用于直接使用 ImageManager,例如 $app['intervention.response']($image)
  • intervention.driver - 使用的驱动程序(imagickgd

测试

$ composer install
$ vendor/bin/phpunit

更新日志

2.0.2

  • README 示例修复。

2.0.0

  • 为 Silex 2.0 更新

1.0.1

  • 修复 Readme
  • 锁定 Silex 到版本 1.1

1.0.0

  • 首次发布

许可证

MIT 许可证 (MIT)