我得到了一个旧的 Symfony 2.3 项目。我以前从未使用过 Symfony(我在 Angularjs 中),所以有点难。
我想要做什么:我需要调整项目,以便我可以显示本地图像或远程图像的缩略图(我将获得已上传图像的完整 url),应该在本地缓存中创建缩略图。
Liip 图像包已在项目中使用,带有过滤器。我用作曲家安装了 KnpGaufretteBundle。
1.在services.yml
services:
acme.liip_imagine.binary.loader.stream.profile_photos:
class: "%liip_imagine.binary.loader.stream.class%"
arguments:
- 'gaufrette://profile_photos/'
tags:
- { name: 'liip_imagine.binary.loader', loader: 'stream.profile_photos' }
2.在config.yml
liip_imagine:
#cache_clearer: false
#cache_mkdir_mode: 0777
loaders:
stream.profile_photos:
stream:
wrapper: gaufrette://profile_photos
filter_sets:
url_thumb:
data_loader: stream.profile_photos
filters:
thumbnail: { size: [100, 100], mode: outbound }
3.in view.twig
// If i display directly the img it works
{% set img = row.path %}
<a href="{{ img }}" class="grouped_elements" rel="group" title="{{ row.copyright }}">
<img src="{{ img }}" width="100px" alt="{{ img }}" border="0" />
</a>
// but i get an error with this :
{% set imgspe = row.path|basename %}
{% set img = ['uploads/'~module.uploaddir~'/', imgspe]|join('') %}
<a href="{{ asset(img) }}" class="grouped_elements" rel="group" title="{{ row.copyright }}">
<img src="{{ asset(img) | imagine_filter('url_thumb') }}" alt="{{ imgspe }}" border="0" />
</a>
错误 :
NetworkError: 404 Not Found - http://publish.test/app_dev.php/media/cache/url_thumb/http://www.jump-voyage.com/wp-content/uploads/2016/06/Google-Images-4.jpg
'Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Source image not found." at /var/www/test/publishv2/vendor/liip/imagine-bundle/Liip/ImagineBundle/Binary/Loader/StreamLoader.php line 55'
所以url不好因为是本地路径+url路径拼接
我能做些什么 ?