Symfony2:在Twig模板中使用LiipImagineBundle与KnpGaufretteBundle和Amaz



我无法让LiipImagineBundle识别流路径。它不加载图像并应用指定的过滤器集,而是采用流路径并将其视为正常的web路径。

这是我能够从各种来源拼凑出来的配置。我找不到任何确切的解决这个问题的方法。就LiipImagineBundle而言,这些设置似乎根本没有取得任何效果。没有抛出任何错误或警告,日志中也没有任何内容。它完全忽略了我的配置。

#/src/Acme/StorageBundle/Resources/config/services.yml
services:
  acme_storage.amazon_s3:
    class:        %acme_storage.amazon_s3.class%
    arguments:
      options:
        key:      %acme_storage.amazon_s3.aws_key%
        secret:   %acme_storage.amazon_s3.aws_secret_key%
        certificate_authority: true
  liip_imagine.binary.loader.stream.amazon_s3:
    class: %liip_imagine.binary.loader.stream.class%
    arguments:
      - @liip_imagine
      - 'gaufrette://amazon_s3/'
    tags:
      - name:   liip_imagine.binary.loader
        loader: stream.amazon_s3
  liip_imagine.cache.resolver.amazon_s3:
    class: LiipImagineBundleImagineCacheResolverAmazonS3Resolver
    arguments:
      - @acme_storage.amazon_s3
      - %amazon_s3_bucket_name%
    tags:
      - name: liip_imagine.cache.resolver
        resolver: cache.amazon_s3
# /app/config/config.yml
knp_gaufrette:
  stream_wrapper:
    protocol:     gaufrette
    filesystems:
      amazon_s3:  photo_storage
  adapters:
    photo_storage:
      amazon_s3:
        amazon_s3_id: beebop_storage.amazon_s3
        bucket_name:  %amazon_s3_bucket_name%
        create:       false
        options:
          create:     true
          region:     %amazon_s3_region%
  filesystems:
    photo_storage:
      adapter:        photo_storage
      alias:          photo_storage_filesystem
liip_imagine:
  cache:              cache.amazon_s3
  loaders:
    stream.amazon_s3:
      stream:
        wrapper:      gaufrette://amazon_s3
  filter_sets:
    cache: ~
    event_small:
      data_loader:    stream.amazon_s3
      quality:        75
      filters:
        thumbnail:
          size:       [60, 60]
          mode:       outbound
          allow_upscale: true

Twig:

{{ 'gaufrette://amazon_s3/file.jpg'|imagine_filter('event_small') }}

产品:

http://example.com/media/cache/resolve/event_small/gaufrette://amazon_s3/file.jpg

我几周前就这么做了,但我没有将s3用于缓存。您的问题似乎与图像路径有关。在树枝上试试这个:

{{ 'file.jpg'|imagine_filter('event_small') }}

由于数据加载程序知道您使用的流,缓存解析程序知道文件所在的URL,因此您只需要传递文件名。

另一个与您的配置不同的地方是,我的配置在gaufrite路径上有一个领先的/

liip_imagine:
  loaders:
    stream.amazon_s3:
      stream:
        wrapper:      gaufrette://amazon_s3/

希望能有所帮助。

相关内容

  • 没有找到相关文章

最新更新