inweb/media

InWeb 框架的媒体组件

9.0.6 2022-08-14 21:04 UTC

This package is auto-updated.

Last update: 2024-09-29 05:28:42 UTC


README

媒体文件操作

需求

  • Laravel >=5.7

安装

  1. 使用 composer require 安装包
    composer require inweb/media
    
    或者将包添加到 composer.json 的 require 部分并更新依赖
    "inweb/media": "*"
    
  2. 运行迁移
    php artisan migrate
    

您已经准备好开始使用!

用法

将特质添加到您的模型(InWeb\Base\Entity)中

use InWeb\Media\WithImages;

为了实现缩略图,实现方法

use InWeb\Media\Thumbnail;

...

public function getImageThumbnails()
{
    return [
        'catalog' => new Thumbnail(function (\Intervention\Image\Image $image) {
            return $image->resize(100, 100, function (Constraint $c) {
                $c->aspectRatio();
                $c->upsize();
            })->resizeCanvas(100, 100);
        }, true),
    ];
}

缩略图类接收2个参数

  1. 闭包,包含 \Intervention\Image\Image 对象
  2. 布尔值 - 仅用于主图片(默认 - false

您可以指定 original 缩略图名称来操作原始图片。

public function getImageThumbnails()
{
    return [
        'original' => new Thumbnail(...),
    ];
}