我已经在Laravel 5.1中安装了干预,我正在使用图片上传并调整大小如下:
Route::post('/upload', function()
{
Image::make(Input::file('photo'))->resize(300, 200)->save('foo.jpg');
});
Run Code Online (Sandbox Code Playgroud)
我不明白的是,干预如何处理上传图像的验证?我的意思是,干预是否已经在其中进行了内置图像验证检查,或者是我需要使用Laravel手动添加Validation来检查文件格式,文件大小等的东西.?我已阅读干预文档,但在使用laravel干预时,我无法找到有关图像验证如何工作的信息.
有人能指出我正确的方向吗...
laravel laravel-5 laravel-validation intervention laravel-filesystem
从远程服务器获取图像时如何获取文件名?以及如何保存原始大小和文件名?
// Take remote image
$img = Image::make('http://image.info/demo.jpg');
// how to save in the img/original/demo.jpg
$img->save(????);
Run Code Online (Sandbox Code Playgroud)
我使用Intervention,(http://image.intervention.io/api/make)构建CakePHP 3图像行为,我想从远程服务器上提供一个简单的上传,并保持原始图像作为未来操作的来源.
编辑
我问,是否存在Intervention Image方法,该方法从远程服务器获取文件的名称.我知道php copy(),我也可以使用CakePHP文件实用程序,但它给了我远程文件的重复请求.
我正在尝试在Laravel 5.1中添加个人资料图片上传.我使用了Intervention/ImagePackage但是当我尝试上传图片时出现此错误:
AbstractDecoder.php第302行中的NotReadableException:图像源不可读
这是我的PhotoController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Image;
use Input;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PhotoController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/ …Run Code Online (Sandbox Code Playgroud) 我有一个关于给定图像的大小调整过程的小问题,我正在尝试提交包含输入类型的表单 - >文件< - 我能够上传图片而不调整大小,之后我决定调整大小图像所以我使用以下方法安装了干预图像库:
composer require intervention/image
Run Code Online (Sandbox Code Playgroud)
然后我将库集成到我的Laravel框架中
Intervention\Image\ImageServiceProvider::class
'Image' => Intervention\Image\Facades\Image::class
Run Code Online (Sandbox Code Playgroud)
最后我配置如下
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
Run Code Online (Sandbox Code Playgroud)
我的控制器如下
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Image;
class ProjectController extends Controller{
public function project(Request $request){
$file = Input::file('file');
$fileName = time().'-'.$file->getClientOriginalName();
$file -> move('uploads', $fileName);
$img=Image::make('public/uploads/', $file->getRealPath())->resize(320, 240)->save('public/uploads/',$file->getClientOriginalName());
}
}
Run Code Online (Sandbox Code Playgroud)
但不是调整图片大小,而是抛出以下异常
NotReadableException in AbstractDecoder.php line 302:
Image source not readable
Run Code Online (Sandbox Code Playgroud) 我需要使用干预图像和laravel将一些图像插入另一个图像.
这是我的主要形象:
这些是我要插入主图像的图像:
最后这个图片插入后:
好吧,我使用这段代码来做到这一点:
$img = Image::make(asset('images/cover.png' ) )->encode('jpg', 15);
$token = Session::get('_token');
$imgWidth = $img->width();
$imgHeight = $img->height();
$coverImages = Storage::allFiles('public/' . $token . '/cover');
$r1 = Image::make(asset('storage/' . $token . '/cover/r1.png') );
$r2 = Image::make(asset('storage/' . $token . '/cover/r2.png') );
$r1->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
});
$r2->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
});
$img->insert($r1, 'top-left', 190, 175);
$img->insert($r2, 'top-left', 290, 175);
$img->save( public_path("storage/{$token}/111111.png"));
Run Code Online (Sandbox Code Playgroud)
现在我需要圆r1.png和r2.png角落,以适应main image.
你知道我怎么能这样做吗?
提前致谢
注意 :
谢谢@Pascal Meunier …
我正在Laravel 5 上使用出色的干预库实现一些图像处理。如果图像很小,比如小于 700KB,宽度小于 800px,它就可以正常工作。
但它无法处理大尺寸图像,我想上传 8 MB 宽、2000 像素宽的图像。
我尝试过经典的碰撞方式,memory_limit但它不起作用
ini_set("memory_limit","20M");
Run Code Online (Sandbox Code Playgroud)
有没有什么解决方案可以在不杀死服务器的情况下工作。
这是我的上传服务的代码。它Request::file('file')使用干预从图像中提取图像并将其调整为 3 个尺寸。
拇指宽 200px
public function photo($file)
{
$me = Auth::user();
//user folder for upload
$userFolder = $me->media_folder;
//Check the folder exist, if not create one
if($this->setupUsrFolder($userFolder)) {
//Unique filename for image
$filename = $this->getUniqueFilename($userFolder);
//Bump the memory to perform the image manipulation
ini_set("memory_limit","20M");
//Generate thumb, medium, and max_width image
$img = Image::make($file);
//big_img …Run Code Online (Sandbox Code Playgroud)我正在将项目从Laravel 5升级到5.1.需要更新的一个包是League\Flysystem.
我Intervention\Image用来调整图像大小,然后使用Flysystem将其保存到S3.下面的代码与5.0一起使用 -
// Album ID
$id = $request->input('id');
// Filename for this photo
$filename = str_random() . ".jpg";
// Get the storage disk
$disk = Storage::disk('s3');
// Resize the photo
$image = Image::make($request->file('photo'));
$image->orientate();
$image->resize(1024, 748, function ($constraint) {
$constraint->aspectRatio();
});
$image->encode('jpg');
// Save the photo to the disk
$disk->put("img/album/$id/$filename", $image);
Run Code Online (Sandbox Code Playgroud)
但现在我收到以下错误:
fstat() expects parameter 1 to be resource, object given,引入league\flysystem\src\Util.php第250行.
我在用"intervention/image": "~2.1","league/flysystem-aws-s3-v3" : "~1.0",
可能导致这种情况的任何想法?
当我上传大图像(4.2 MB)干预图像投掷500错误...
private function resizeImage($path, $imgName){
$sizes = getimagesize($path.$imgName);
if($sizes[0] > $sizes[1]){
ImageManagerStatic::make($path.$imgName)->fit(920,474)->insert(public_path() . "/uploads/applications/watermark.png",'bottom-right', 30, 30)->save($path."1_".$imgName);
}else{
ImageManagerStatic::make($path.$imgName)->heighten(474)->insert(public_path() . "/uploads/applications/watermark.png",'bottom-right', 30, 30)->save($path."1_".$imgName);
}
ImageManagerStatic::make($path.$imgName)->fit(440,226)->save($path."2_".$imgName);
File::delete($path.$imgName);
}
Run Code Online (Sandbox Code Playgroud)
它适用于较小的文件.upload_max_filesize=10M.当我评论这个功能时它起作用:/
我正在尝试创建上传图像的水印版本,并使用 laravel 5.6 和 Intervention 将它们存储到存储文件夹中。
//create the watermarked image
$watermarkedImage = Image::make($request->file('photo'));
$watermark = Image::make(Storage::get('watermark.png'));
$watermark->widen(floor(($watermarkedImage->width() / 4) * 3));
$watermarkedImage->insert($watermark, 'center');
//save the watermarked and standard image to disc and recording their names for db
$location = $request->file('photo')->store('public/uploads');
$fileName = md5($location . microtime());
$extension = '.' . explode("/", $watermarkedImage->mime())[1];
$watermarkedLocation = Storage::putFileAs('public/watermarked/', $watermarkedImage, $fileName . $extension);
Run Code Online (Sandbox Code Playgroud)
每当我尝试运行此代码时,我都会收到错误:
命令 (GetRealPath) 对驱动程序 (Gd) 不可用
我还尝试在 watermardImage 变量上使用 ->save() 和 ->store() 命令,但出现了错误:
无法将图像数据写入路径(public/watermarked/6b2492b7856c4d68ea15509c5b908a8c.png)
和
命令(存储)不可用于驱动程序 (Gd)
任何帮助将不胜感激
编辑:忘记添加它成功保存了没有水印的原始图像
我正在使用Laravel图像处理包干预图像.
我想将裁剪后的图像保存到变量然后再保存到DB但是在文档中找不到如何将结果导出为字符串.这是我的代码:
$img = Image::make($uploadedImage);
$img->crop(160, 210);
$imageEncoded = // ?
Run Code Online (Sandbox Code Playgroud)
有save(),但它只保存到文件.
如何将修改后的干预图像导出到字符串变量?(data:image/jpeg;base64,…)
intervention ×10
laravel ×7
php ×7
laravel-5 ×3
image ×2
laravel-5.2 ×2
base64 ×1
cakephp-3.1 ×1
file-upload ×1
flysystem ×1
laravel-5.1 ×1
laravel-5.4 ×1