2012-10-10 19 views
5

我使用VichUploaderBundle上傳我的媒體文件,我想使用AvalancheImagineBundle在我的模板中創建大拇指。 應該怎麼做?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 } 

任何幫助或線索?

回答

2

如果你遇到的問題是沒有圖像顯示,那麼我有同樣的問題。

爲了解決它,我保證我的config.yml內,avalanche_imagine的source_rootweb_root選項被設置爲%kernel.root_dir%/../web(或您的Web根目錄)。這裏是我的config.yml相關片段:

#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 
0

沒有錯。試想一下,生產中的捆綁包第一次生成縮略圖並將其存儲在web/media文件夾中。在第二次調用它只是從網絡/媒體讀取。 它有一些優點,可以隨意修改thumnail大小。如果您擔心表現不佳,您應該在上傳完成後解僱一些工作以生成縮略圖, 儘管我使用它並且從未投訴過。

+0

但輸出不正確:Froga ikerib

+0

如果您處於開發模式,它將添加app_dev.php。第一次調用生成圖像,第二次調用和休息是301重定向到生成的文件。 – Michal

0

就我而言,我選擇使用LiipImagineBundle這是AvalancheImagineBundle 的一個分支。

我將這個包配置爲使用gaufrette作爲數據加載器,而不是像你描述的那樣簡單地使用它,而不關心路徑。

相關問題