我将图像上传到我的S3服务器没有问题(因此我知道我的图像路径是合法的),但是当我尝试使用Liip / Imagine服务创建一些调整大小的图像时,Liip / Imagine可以找不到我上传的图片。
我对图像路径进行如下转储:
$idFile = $form['idFile']->getData();
dump($idFile);
die();
这是转储的样子:
ProfileController.php on line 340:
UploadedFile {#64 ▼
-test: false
-originalName: "file-name.png"
-mimeType: "image/png"
-error: 0
path: "/tmp"
filename: "php09sJr3"
basename: "php09sJr3"
pathname: "/tmp/php09sJr3"
extension: ""
realPath: "/tmp/php09sJr3"
aTime: 2019-02-24 22:54:00
mTime: 2019-02-24 22:54:00
cTime: 2019-02-24 22:54:00
inode: 12586620
size: 97901
perms: 0100600
owner: 997
group: 995
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
我知道此路径(/ tmp / php09sJr3)是合法的,因为我的文件都完美地上传到了我的S3存储桶,但是当我尝试在控制器中创建缩略图时:
public function saveProfileEditAction(Request $request, FilterService $imagine)
{
$form = $this->createForm(UserProfileType::class, $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$idFile = $form['idFile']->getData();
if ($idFile != null){
// this command right here
$resourcePath = $imagine->getUrlOfFilteredImage($idFile->getPathName(), 'my_thumb');
我收到以下错误:
Source image not resolvable "/tmp/php09sJr3" in root path(s) "/var/www/vhosts/mywebsite.com/public"
更令人困惑的是,当我检查时,/tmp
或/var/www/vhosts/mywebsite.com/public/tmp
中没有任何内容,但是我的文件仍然完美地上传到了S3。
这是我的配置liip_imagine.yaml文件:
liip_imagine :
# configure resolvers
resolvers :
# setup the default resolver
default :
# use the default web path
web_path : ~
# your filter sets are defined here
filter_sets :
# use the default cache configuration
cache : ~
# the name of the "filter set"
my_thumb :
# adjust the image quality to 75%
quality : 75
# list of transformations to apply (the "filters")
filters :
# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail : { size : [120, 90], mode : outbound }
thumb_square : { size : [300, 300], mode : outbound }
thumb_rectangle_md : { size : [670, 400], mode : outbound }
thumb_hd : { size : [1920, 1080], mode : outbound }
# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [124, 94], position : center, color : '#000000' }
如何正确告诉Liip / Imagine我上传的文件的文件路径?
答案 0 :(得分:0)
您必须将其添加到您的yaml配置文件中(我的文件名为liip_imagine.yaml):
loaders:
default:
filesystem:
data_root: "/"
因此在文件范围内,它看起来像:
liip_imagine :
# configure resolvers
resolvers :
# setup the default resolver
default :
# use the default web path
web_path : ~
# !!!!!!!!!!!!!!!!!!!!!START!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
loaders:
default:
filesystem:
data_root: "/"
# !!!!!!!!!!!!!!!!!!!!!END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# your filter sets are defined here
filter_sets :
# use the default cache configuration
cache : ~
# the name of the "filter set"
my_thumb :
# adjust the image quality to 75%
quality : 75
# list of transformations to apply (the "filters")
filters :
# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail : { size : [120, 90], mode : outbound }
resize : { size : [670, 400], mode : outbound }
# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [124, 94], position : center, color : '#000000' }
Liip然后将创建缩略图,调整大小等...并将文件移动到:
http://www.yourwebsite.com/media/cache/my_thumb/tmp/phpSQFUF1
从技术上讲,它将位于根文件夹中的/public/media/cache/my_thumb/tmp
文件夹中。