繁体   English   中英

如何获取我使用 Laravel 中的存储外观访问的 AWS S3 中图像的尺寸?

[英]How do I get the dimensions of an image in AWS S3 that I'm accessing with the Storage facade in Laravel?

我有一些图像存储在 AWS S3 中,我使用 Laravel 中的存储外观在网页上显示它们。

在某些情况下,我想获取一些图像的尺寸并将这些尺寸存储在数据库中。

我想在 PHP 中使用getimagesize函数,但图像不是公开可用的,只能通过 Storage 门面访问它们。

如何获得这些图像的尺寸? 谢谢你。

编辑:我应该提到这个图像处理都是为了数据库迁移而完成的,所以使用像 JS 这样的 Web 前端解决方案来获取图像尺寸是不切实际的。

我想出了一个似乎有效的解决方案。 基本上,我使用 Storage 外观获取文件的二进制文件,然后使用imagecreatefromstringimagesximagesy函数来获取图像的宽度和高度。

下面是一个例子:

$contents = Storage::get($storageFilePath);
$im = imagecreatefromstring($contents);
$width = imagesx($im) ?? null;
$height = imagesy($im) ?? null;

您还可以使用开源库Intervention\\Image ,它使用 GD 库和 Imagick:

$image = \Image::make(Storage::get($storageFilePath));
$width = $image->width();
$height = $image->height();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM