我将图像保存到 s3 并将 s3 路径保存到我的数据库。当我需要显示图像时,我正在调用路径。所以现在我在将其保存到 s3 之前无法调整该图像的大小。我收到此错误消息:
Command (getRealPath) is not available for driver (Gd).
这就是我的控制器的样子
public function up(Request $request) {
$user = $request->user();
$image= $request->file('images');
if(!empty(($image))){
$files = Input::file('images');
foreach($files as $file) {
if(!empty($file)){
$ext = $file->getClientOriginalExtension();
$media = ($user->media->where('category','profile')->first());
if($media == null){
$media = new Media();
$media->category='profile';
}
$this->saveMedia($media, $user,$file);
}
}
return Redirect::back()->with('message','Your profile has been updated');
}
}
private function saveMedia($media, $user, $file){
$ext = $file->getClientOriginalExtension();
$key = strtotime('now') . '.' . $ext;
$id = $user->id;
$url = 'https://s3-us-west-2.amazonaws.com/makersbrand/' . $id . '/' . $media->category . '/';
$media->user_id = $user->id;
$media->path = $url . $key;
$this->fillMedia($media,$user,$file, $key);
$media->save();
}
private function fillMedia($media, $user, $file, $key)
{
$file = Image::make($file)->resize(200,200);
$s3 = AWS::createClient('s3');
$result = $s3->putObject(array(
'Bucket' => self::$_BUCKET_NAME,
'Key' => $user->id . '/'. $media->category .'/'. $key,
'SourceFile' => $file->getRealPath(),
'Metadata' => array(
'Owner' => $user->first_name .' ' . $user->last_name
)
));
}
更新 我认为我的图像在遇到 getClientOriginalExtension 错误之前甚至无法正确调整大小。当我在调整大小后做 var_dump 时,我得到这个文本:
object(Intervention\Image\Image)#238 (9) { ["driver":protected]=>
object(Intervention\Image\Gd\Driver)#237 (2) { ["decoder"]=>
object(Intervention\Image\Gd\Decoder)#241 (1) {
["data":"Intervention\Image\AbstractDecoder":private]=> NULL }
["encoder"]=> object(Intervention\Image\Gd\Encoder)#242 (4) { ["result"]=>
NULL ["image"]=> NULL ["format"]=> NULL ["quality"]=> NULL } }
["core":protected]=> resource(280) of type (gd) ["backups":protected]=>
array(0) { } ["encoded"]=> string(0) "" ["mime"]=> string(10) "image/jpeg"
["dirname"]=> string(26) "/Applications/MAMP/tmp/php" ["basename"]=>
string(9) "phpVGzVk0" ["extension"]=> NULL ["filename"]=> string(9)
"phpVGzVk0" }
结果为空。格式为空。图像为空。我在这里做错了什么?
更新 我将 Image::make 移动到我的 saveMedia 函数。现在我明白了
Command (getRealPath) is not available for driver (Gd).