【问题标题】:How to resize the image size on browser using Laravel 5.2?如何使用 Laravel 5.2 在浏览器上调整图像大小?
【发布时间】:2016-12-22 16:38:01
【问题描述】:

我在我的项目中使用 laravel 5.2。但是现在我在我的项目中面临一个问题是页面上的图像获取。在我的主页上显示图像的项目中,但图像大小超过 2mb,并且显示图像需要时间。所以有人建议使用 grunt 来调整图像大小。而且我不知道什么是 grunt 以及如何使用?我试图找到没有得到正确解决方案的咕噜声。请给我建议。

【问题讨论】:

  • Grunt 是一个任务自动化工具。 Grunt 有一个名为imagemin 的包,它将根据您提供的设置为您优化图像。还有Grunt's official site

标签: javascript php jquery laravel laravel-5.2


【解决方案1】:

你可以在 Laravel 中使用 Intervention Image。从this tutorial 开始,了解如何上传和调整图像大小。本教程中的这段代码可能会有所帮助:

$image = $request->file('image');
    $input['imagename'] = time().'.'.$image->getClientOriginalExtension();

$destinationPath = public_path('/thumbnail');
$img = Image::make($image->getRealPath());
$img->resize(100, 100, function ($constraint) {
    $constraint->aspectRatio();
})->save($destinationPath.'/'.$input['imagename']);

$destinationPath = public_path('/images');
$image->move($destinationPath, $input['imagename']);

【讨论】:

  • 感谢您的回复,但是有什么办法可以在浏览器上调整图像大小
  • 您可以在浏览器中通过设置图片的宽度来调整图片大小,但不会影响加载速度。通常你想调整/优化上传的图片。
  • 我可以用 Laravel Elixir 吗
猜你喜欢
  • 2012-06-13
  • 2017-03-14
  • 2013-08-11
  • 1970-01-01
  • 1970-01-01
  • 2011-10-04
  • 2018-06-19
  • 1970-01-01
  • 2015-09-03
相关资源
最近更新 更多