当我写一个代码来在刀片文件中显示图像时,图像缩略图制作的时间,我可以给出每次我需要图像的高度,宽度,这样我就可以在单个站点生成同一图像的多个拇指。
{{$page->image,100,100)}}
或
<td><?php if ($page->image) { ?><img src="{{ url('/upload/pages/'.$page->image,100,200) }}"/><?php } ?></td>
请提前给出如何制作这种缩略图的建议。
发布于 2018-02-08 17:56:57
您需要进行干预,然后在您的上传控制器中放入如下内容:
...
$file = $request->file('files');
$extension = $file->getClientOriginalExtension();
Storage::disk('local')->put('/'.$file->getFilename().$extension, File::get($file));
$thumb1 = ImageManagerStatic::make($file->getRealPath())->resize(200, 200, function ($constraint) {
$constraint->aspectRatio(); //maintain image ratio
})->save('thumb1'.$extension);
$thumb2 = ImageManagerStatic::make($file->getRealPath())->resize(400, 400, function ($constraint) {
$constraint->aspectRatio(); //maintain image ratio
})->save('thumb2'.$extension);
...
发布于 2018-02-08 18:12:20
您可以使用微服务动态调整图像大小,并将缩略图缓存到CDN中。请看一下here
<img src="{{ imgProxy('https://your-microservice.com/your-image.jpg', 100, 200) }}"/>
发布于 2019-06-13 04:04:50
仅供记录,如果您使用的是Laravel,一个好的选择是使用intervention/image和intervention/imagecache包。
您需要的内容在Intervention Image Docs的“基于URL的图像操作”一节中进行了描述。
https://stackoverflow.com/questions/34659502
复制相似问题