我想将 google plus 中的图像保存为下面的 url,它在本地计算机上也能正常工作,但在上传到 ubuntu14 时出现以下错误。
$image = Image::make('https://lh6.googleusercontent.com/-Gcp_Wjj7yA0/AAAAAAAAAAI/AAAAAAAAAB8/hl1xcz4FnEI/photo.jpg')
->resize(100, 100)->save(public_path('image/userface/fuck.jpg'));
Run Code Online (Sandbox Code Playgroud)
错误
Unable to init from given url
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Intervention 来调整图像大小,然后将其保存在我定义的磁盘中,但我无法让它工作。使用 public_folder 将其保存在我的应用程序根目录中名为 /public 的文件夹中。
我创建了一个新磁盘
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'visibility' => 'public',
],
Run Code Online (Sandbox Code Playgroud)
我需要接受用户的输入,然后将他们上传的文件保存到该磁盘,然后将文件路径保存到数据库。
$fieldFile = $request->file($fieldName);
$imageName = time();
Image::make($fieldFile)->crop(350, 350)->save(public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension());
$object->$fieldName = public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension();
Run Code Online (Sandbox Code Playgroud)
我想最终得到类似于应该发生的事情
$fieldValue = $fieldFile->store($fieldName, 'images'); …Run Code Online (Sandbox Code Playgroud) 当用户上传他的个人资料图片时,我想为这张图片创建 3 个不同尺寸的版本,然后将所有内容上传到亚马逊 s3。
我使用图像干预包来调整图像大小,这是我目前的代码。
public function store(Request $request){
if($request->has('avatar')){
$avatar = $request->file('avatar');
$filename = md5(time()).'_'.$avatar->getClientOriginalName();
$normal = Image::make($avatar)->resize(160, 160);
$medium = Image::make($avatar)->resize(80, 80);
$small = Image::make($avatar)->resize(40, 40);
Storage::disk('s3')->put('/users/'.Auth::user()->uuid.'/avatars/normal/'.$filename, fopen($normal, 'r+'), 'public');
Storage::disk('s3')->put('/users/'.Auth::user()->uuid.'/avatars/medium/'.$filename, fopen($medium, 'r+'), 'public');
Storage::disk('s3')->put('/users/'.Auth::user()->uuid.'/avatars/small/'.$filename, fopen($small, 'r+'), 'public');
$user = User::findorFail(Auth::user()->id);
$user->avatar = $filename;
$user->save();
return redirect()->back();
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试提交文件时,出现此错误。
fopen(): Filename cannot be empty
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏
当用户上传图片时,我想以多种格式存储它。我处理图像的代码:
$img = Image::make($file)->encode('png');
if($img->width()>3000){
$img->resize(3000, null, function ($constraint) {
$constraint->aspectRatio();
});
}
if($img->height()>3000){
$img->resize(null, 3000, function ($constraint) {
$constraint->aspectRatio();
});
}
$uid = Str::uuid();
$fileName = Str::slug($item->name . $uid).'.png';
$high = clone $img;
Storage::put( $this->getUploadPath($bathroom->id, $fileName, "high"), $high);
$med = clone $img;
$med->fit(1000,1000);
Storage::put( $this->getUploadPath($bathroom->id, $fileName, "med"), $med);
$thumb = clone $img;
$thumb->fit(700,700);
Storage::put( $this->getUploadPath($bathroom->id, $fileName, "thumb"), $thumb);
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试了一些变体。
我也试过:
$thumb = clone $img;
$thumb->resize(400, 400, function ($constraint) {
$constraint->aspectRatio();
});
Storage::put( $this->getUploadPath($fileName, "thumb"), $thumb);
Run Code Online (Sandbox Code Playgroud)
getUploadPath 函数:
public function …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的文件上传为圈子,但我无法使其正常工作.我已经看到了一些关于将掩码应用于图像的主题,但是当我应用掩码时,它需要很长时间并且服务器关闭请求.
我正在使用Intervention ImageLaravel 的库
我的代码如下:
$identifier = "{$this->loggedUser->id}" . str_random(9) . ".{$file->getClientOriginalExtension()}";
$mask = $this->createCircleMask(200, 200);
$thumbMask = $this->createCircleMask(40, 40);
Image::make($file->getRealPath())->mask($mask)->save(public_path("images/profile/{$identifier}"));
Image::make($file->getRealPath())->mask($thumbMask)->save(public_path("images/profile/thumbs/{$identifier}"));
Run Code Online (Sandbox Code Playgroud)
该createCircleMask方法如下所示:
public function createCircleMask($width, $height)
{
$circle = Image::canvas($width, $height, '#000000');
return $circle->circle($width - 1, $width / 2, $height / 2);
}
Run Code Online (Sandbox Code Playgroud) 我将图像保存到 s3 并将 s3 路径保存到我的数据库。当我需要显示图像时,我正在调用路径。所以现在我在将其保存到 s3 之前无法调整该图像的大小。我收到此错误消息:
Command (getRealPath) is not available for driver (Gd).
Run Code Online (Sandbox Code Playgroud)
这就是我的控制器的样子
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; …Run Code Online (Sandbox Code Playgroud) 使用 Vagrant 和 Homestead 运行 Laraval 5.4。
看到了有关此问题的其他一些问题,但没有一个提供使用Intervention/Image的canvas()方法的解决方案
我目前的代码:
$path = $request->file('logo')->store('/clients/logos','public');
$canvas = Image::canvas($width, $height);
$image = Image::make($path)->resize($width, $height, function ($constraint)
{
$constraint->aspectRatio();
});
$canvas->insert($image, 'center');
$canvas->save($path);
$this->logo_path = $path;
Run Code Online (Sandbox Code Playgroud)
此代码创建一个画布并在其中放置一个调整大小的图像。
此代码给出以下错误:
在 AbstractDecoder.php 第 335 行中的 NotReadableException:在 AbstractDecoder->init('clients/logos/UupUn1iuDGRsy5Z0bkWHJ6S4v79bfZiXapTO7vLk.jpeg') 在 AbstractDriver.php 行中,AbstractDecoder.php 第 335 行中的图像源不可读
第一行有效,因为图像存储在我的存储文件夹中的以下位置:
“/storage/app/public/clients/logo/UupUn1iuDGRsy5Z0bkWHJ6S4v79bfZiXapTO7vLk.jpeg”
但是图像以全尺寸存储,因此代码在图像干预部分失败。
我尝试过的事情:我尝试将$pathImage::make() 中的变量更改为:
Storage::disk('public')->url($path)
Run Code Online (Sandbox Code Playgroud)
这导致以下错误:无法将图像数据写入路径
( http://test.dev/storage/clients/logos/owjNA5Fn9QyYoS0i84UgysaFLo5v0NzbOiBhBzXp.jpeg )
关于该错误的奇怪部分是“app”目录在该错误中不可见。
我已经没有想法来解决这个问题了。
在不使用画布的情况下工作,但仍然想知道使用 canvas() 的方法
这就是我目前让它工作的方式:
$path = $logo->hashName('public/clients/logos');
$image = Image::make($logo);
$image->resize($width, $height, …Run Code Online (Sandbox Code Playgroud) 我在我的用户模型中创建了一个方法来为用户上传海报(有干预):
/**
* Store user's poster.
*/
public static function storePoster(Request $request)
{
if($request->hasFile('posterUpload')){
$poster = $request->file('posterUpload');
$filename = time() . '.'. $poster->getClientOriginalExtension();
Image::make($poster)->resize(356,265)->save(public_path('/uploads/posters/'.$filename));
$check = Setting_user::where([
['user_id', '=' ,Auth::user()->id],
['setting_id','=', 2],
])->first();
if(!$check)
{
$setting = new Setting_user();
$setting->user_id = Auth::user()->id;
$setting->setting_id = 2;
$setting->value = $filename;
$setting->save();
return back();
}
$check->value = $filename;
$check->update();
return back();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的UserController中,我有另一个方法来调用在User模型中创建的静态方法:
/**
* Store user's poster.
*/
public function poster(Request $request)
{
User::storePoster($request);
}
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
Route::post('/user-profile/store/poster', 'UserController@poster');
Run Code Online (Sandbox Code Playgroud)
这是我导航到"/ user-profile/store/poster"时出现的错误:
Argument …Run Code Online (Sandbox Code Playgroud) 我创建了一个上传图像以及标题、描述等的应用程序。但是,我在上传某些图像时遇到问题,它返回错误(“图像源不可读”),如下所示:
这是我的代码:
$image = $request->file('image');
// $image = Input::file('image'); // already tried this one still same problem
$orginal_filename = $image->getClientOriginalName();
$ext = $image->getClientOriginalExtension();
$fileName = md5(microtime() . $orginal_filename) . '.' . $ext;
$img = Image::make($image->getRealPath());
$img->stream();
$img->resize(1200, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('storage_dir')->put($dir . $fileName, $img, 'public');
Run Code Online (Sandbox Code Playgroud)
已经尝试过以下解决方案:
但仍然有“图像源不可读”错误。
注意:错误仅发生在某些图像中。(我还尝试将图像(w/c 产生错误)移动到另一个目录中,但仍然出现错误)。
十分感谢你的帮助!
我正在上传一个 iPhone 图像 - 由 iPhone 相机垂直拍摄 - 尺寸为2448x3264并且因为这个尺寸太高(?),当我创建600x360它的拇指时它会自动旋转到水平。
我试过什么没有成功:
fit功能resize功能crop功能upsize和aspectRatio方法height和使用 null onwidthwidth和使用 null onheight拇指的最大高度必须为360,如果宽度不是 ,我就可以了600。
$imageResize = Image::make($originalFile);
$imageResize->fit(600, 360, function ($constraint)
{
$constraint->upsize();
});
$imageResize->save($thumbPath);
Run Code Online (Sandbox Code Playgroud)
我的目标是:
我怎样才能做到这一点?
intervention ×10
laravel ×8
php ×6
laravel-5 ×4
amazon-s3 ×2
image ×2
eloquent ×1
laravel-5.3 ×1
laravel-5.4 ×1
laravel-5.7 ×1
request ×1