weysan/doctrine-img-bundle

利用 doctrine 实体中的注解创建缩略图的辅助工具

此软件包的官方仓库似乎已消失,因此该软件包已被冻结。

安装: 135

依赖者: 0

建议者: 0

安全: 0

星标: 4

关注者: 3

分支: 2

开放问题: 0

类型:symfony-bundle

v1.2-beta 2016-07-25 09:02 UTC

This package is not auto-updated.

Last update: 2023-02-04 09:23:52 UTC


README

在 Symfony3 项目中通过表单上传图片后创建缩略图

安装软件包

使用 composer

composer require weysan/doctrine-img-bundle

在 app\AppKernel.php 中启用软件包

$bundles = array(
            ...,
            new Weysan\DoctrineImgBundle\WeysanDoctrineImgBundle(),
            ...,
        );

在您的 app\config\config.yml 中导入配置文件

imports:
	- { resource: "@WeysanDoctrineImgBundle/Resources/config/config.yml" }
    - { resource: "@WeysanDoctrineImgBundle/Resources/config/services.yml" }

您可以在 config.yml 文件中指定公共目录的位置

weysan_doctrine_img:
    public_root: %kernel.root_dir%/../web/

如何使用它?

创建您的 doctrine 实体,并添加注解

@ImgResize("image", width="500", height="300", uploadDir="media/upload/article", uploadDirDate=true, saveField="path", strict=true, crop=false)
  • image : 添加注解的字段
  • width : 缩略图的宽度
  • height : 缩略图的高度
  • strict : (true 或 false,默认为 true) 如果 strict 为 true,则缩略图将具有严格的高度和宽度。如果 strict 为 false,则高度和宽度将是保存的缩略图的最大尺寸。
  • crop : (true 或 false,默认为 false) 您是否希望缩略图可以被裁剪(如果 strict 设置为 true,则很有用)
  • uploadDir : 存放缩略图的目录(在公共目录中)
  • uploadDirDate : (true 或 false,默认为 false) 如果目录通过日期(uploadDir/YYYY/MM/)管理文件夹,则 uploadDirDate 为 true。文件夹必须存在。
  • saveField : 存储缩略图名称的实体字段