在Laravel 8应用程序中使用spatie/laravel-medialibrary 8,我想知道是否有办法获得上传图像的尺寸(宽度*高度)?
提前感谢!
发布于 2021-12-13 08:27:44
我还没测试过密码。
空间MediaLibrary在后台使用空间图像包生成响应图像。
所以你可以做这样的事。
$fullPathToImage = 'your-path-here';
$imageInstance = Spatie\MediaLibrary\Support\ImageFactory::load($fullPathToImage);
$imageWidth = $imageInstance->getWidth();
$imageHeight = $imageInstance->getHeight();因为我还没测试过密码。但它将为你提供一个解决问题的起点。
发布于 2022-06-20 10:14:35
方框中没有这样的特性,但是可以像这样使用spatie/image组件(这是一个依赖项)来获取维度。
下面是我的项目的工作代码:
use Spatie\Image\Image;
class YourController extends Controller
{
public function store(Request $request, string $id)
{
$model = \App\Models\MyModel::find($id);
$image = Image::load($request->file->getPathname());
$width = $image->getWidth();
$height = $image->getHeight();
$media = $model->addMediaFromRequest('file')
->toMediaCollection($collectionName);
// ...
}
}链接到详细信息:https://github.com/spatie/laravel-medialibrary/discussions/2682
https://stackoverflow.com/questions/70321923
复制相似问题