shadesoft/image-bundle

此包已被废弃,不再维护。作者建议使用 sbolch/gd-image 包。

当其他解决方案失败时,使用 PHP 的 GD 库进行图像编辑的包。

v1.3.1 2020-06-07 22:57 UTC

This package is auto-updated.

Last update: 2023-10-27 15:00:56 UTC


README

废弃 - 请使用 GDImage 代替。

当其他解决方案失败时,使用 PHP 的 GD 库进行图像编辑的包。

Latest Stable Version Build Status StyleCI Total Downloads License

安装

步骤 1:下载包

打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

$ composer require shadesoft/image-bundle

此命令需要您已全局安装 Composer,如 Composer 文档中的安装章节中所述。

步骤 2:启用包

然后,通过将其添加到项目 app/AppKernel.php 文件中注册的包列表中来启用该包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new ShadeSoft\ImageBundle\ShadeSoftImageBundle(),
        );

        // ...
    }

    // ...
}

使用方法

使用 PHP

<?php
// src/Acme/DemoController.php

// ...
class DemoController extends Controller
{
    public function DemoAction(Request $request) {
        $img = '../../web/assets/temp.jpg';

        $imgSizer = $this->get('shadesoft_image.sizer');

        $imgSizer->thumbnail($img, 400, 300);
    }
}

使用 Twig

{{ asset('/path/to/image'|thumbnail(400, 300)) }}
{# recommended to use with cache functionality enabled, see below #}

有关使用详情,请参阅 shadesoft/gd-image 文档的 '参数' 和 '可用函数' 部分

缓存

要启用缓存,只需像下面这样配置包即可

# app/config/config.yml for Symfony 2/3, and config/packages/shade_soft_image.yaml for Symfony 4

shade_soft_image:
    cache_directory: /path/to/desired/cache/directory