【问题标题】:VichUploaderBundle and AvalancheImagineBundleVichUploaderBundle 和 AvalancheImagineBundle
【发布时间】:2012-10-10 18:34:50
【问题描述】:

我使用 VichUploaderBundle 上传我的媒体文件,我想使用 AvalancheImagineBundle 在我的模板中创建缩略图。 应该怎么做?

我现在有这个:

<td><img src="{{ vich_uploader_asset(entity, 'image') | apply_filter('my_thumb')}}" alt="{{ entity.nombre }}" /></td>

但是输出是:

<img src="/app_dev.php/media/cache/my_thumb/images/uploads/392158_10150441208223772_580903771_8591661_774015725_n.jpg" alt="Froga"/>

这是我的 config.yml:

# Vich Uploader
vich_uploader:
    db_driver: orm
    twig: true
    gaufrette: false # set to true to enable gaufrette support
    storage: vich_uploader.storage.file_system
    mappings:
        uploads:
            uri_prefix: /images/uploads
            upload_destination: %kernel.root_dir%/../web/images/uploads
            namer: ~ # specify a file namer service id for this entity, null default
            directory_namer: ~ # specify a directory namer service id for this entity, null default
            delete_on_remove: true # determines whether to delete file upon removal of entity
            inject_on_load: true # determines whether to inject a File instance upon load

avalanche_imagine:
    source_root:  %kernel.root_dir%/../web/images/uploads
    web_root:     %kernel.root_dir%/../web/images/uploads
    cache_prefix: media/cache
    driver:       gd
    filters:
        my_thumb:
            type:    thumbnail
            options: { size: [120, 90], mode: outbound, quality: 100, format: png }

任何帮助或线索?

【问题讨论】:

    标签: symfony symfony-2.1


    【解决方案1】:

    如果您遇到的问题是没有显示图像,那么我遇到了同样的问题。

    为了解决这个问题,我确保在我的 config.yml 中,avalanche_imagine 的 source_rootweb_root 选项设置为 %kernel.root_dir%/../web(或您的 Web 根目录)。这是我的 config.yml 中的相关 sn-p:

    #Uploads
    knp_gaufrette:
        adapters:
            article_adapter:
                local:
                    directory: %kernel.root_dir%/../web/images/articles
        filesystems:
            article_image_fs:
                adapter:    article_adapter
    vich_uploader:
        db_driver: orm
        gaufrette: true
        storage: vich_uploader.storage.gaufrette
        mappings:
            article_image:
                uri_prefix: /images/articles
                upload_destination: article_image_fs
                namer: vich_uploader.namer_uniqid
    
    #images
    avalanche_imagine:
        filters:
            article_list:
                type:    thumbnail
                options: { size: [100, 100], mode: outbound }
        source_root:  %kernel.root_dir%/../web
        web_root:     %kernel.root_dir%/../web
        cache_prefix: cache
    

    【讨论】:

      【解决方案2】:

      这没有错。想象一下,生产中的捆绑包在第一次调用时会生成缩略图并将其存储在 web/media 文件夹中。在第二次调用时,它只是从网络/媒体中读取。 随意修改缩略图大小有一些优点。如果您担心性能,您应该在上传完成后触发一些工作以生成缩略图, 虽然我就是这么用的,从来没有抱怨过。

      【讨论】:

      • 但输出不正确:跨度>
      • 如果您处于开发模式,它将添加 app_dev.php。第一次调用生成图像,第二次调用,其余为 301 重定向到生成的文件。
      【解决方案3】:

      就我而言,我选择使用LiipImagineBundle,它是AvalancheImagineBundle 的一个分支。

      我将此捆绑包配置为使用 gaufrette 作为数据加载器,而不是像您描述的那样简单地使用它,而不关心路径。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多