我一直在研究几个小时,无法掌握如何在Symfony2中进行有效的图像处理。 Liip Imagine捆绑似乎是要走的路,但我似乎无法让它在开发中适合我。
我想要的是什么:
我看过以下内容:
app_dev.php
,并且不会尝试保存它的缓存版本。配置:
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
my_thumb:
quality: 75
filters:
thumbnail: { size: [120, 90], mode: outbound }
尝试过Twig:
img src="{{ asset(file.webPath) | imagine_filter('my_thumb') }}"
EDIT !!
所以我使用以下代码尝试从我粘贴的上述帖子上传代码:
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)
引发了以下错误:
mime类型的图片上传/ files / pic_05052015_827_c6d4b.jpg必须是image / xxx得到的inode / x-empty。
我对这些深刻的图像有些迷失。