我已经研究了几个小时,无法掌握如何在 Symfony2 中进行一些有效的图像处理。Liip Imagine 捆绑包似乎是要走的路,但我似乎无法让它在开发中为我正常工作。
我想要的是:
- 在上传时创建图像大小,最好基于 %(我宁愿这样做等待图像请求,因为如果它很大,我不希望那个人在缓存时等待)
- 在图像上创建水印
- 从图像、尺寸、DI 等中检索元数据。
我看过以下内容:
- 上传后使用 LiipImagineBundle 调整图像大小?但是在尝试时我得到一个错误 PHP EXIF extension is required to use the ExifMetadataReader
- http://symfony.com/doc/master/bundles/LiipImagineBundle/index.html但是当尝试在 Twig 中引用它时,它会
app_dev.php
在图像前面添加 并且不会尝试保存它的缓存版本。
配置:
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
my_thumb:
quality: 75
filters:
thumbnail: { size: [120, 90], mode: outbound }
尝试的树枝:
img src="{{ asset(file.webPath) | imagine_filter('my_thumb') }}"
编辑!!
因此,我使用以下代码尝试从我粘贴的上述帖子上传时执行此操作:
private function writeThumbnail($document, $filter) {
$path = $document->getWebPath(); // domain relative path to full sized image
$tpath = $document->getRootDir().$document->getThumbPath(); // absolute path of saved thumbnail
$container = $this->container; // the DI container
$dataManager = $container->get('liip_imagine.data.manager'); // the data manager service
$filterManager = $container->get('liip_imagine.filter.manager');// the filter manager service
$image = $dataManager->find($filter, $path); // find the image and determine its type
$response = $filterManager->get($this->getRequest(), $filter, $image, $path); // run the filter
$thumb = $response->getContent(); // get the image from the response
$f = fopen($tpath, 'w'); // create thumbnail file
fwrite($f, $thumb); // write the thumbnail
fclose($f); // close the file
}
现在这一行$image = $dataManager->find($filter, $path)
抛出以下错误:
image uploads/files/pic_05052015_827_c6d4b.jpg 的 mime 类型必须是 image/xxx got inode/x-empty。
我对这些深层次的图像有点迷茫。