creode/laravel-assets

用于DAM创建资源的基模块。

1.8.1 2024-04-18 08:30 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这里应该放置你的描述。限制在一两段之内。考虑添加一个小的示例。

安装

您可以通过composer安装此包

composer require creode/laravel-assets

您可以使用以下命令发布并运行迁移

php artisan vendor:publish --tag="assets-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="assets-config"

这是发布配置文件的内容

return [

    /*
    |--------------------------------------------------------------------------
    | Disk
    |--------------------------------------------------------------------------
    |
    | This value is the name of the disk where assets will be stored. This can
    | be any disk that you have configured in your filesystems.php config file.
    |
    */

    'disk' => env('FILESYSTEM_DISK', 'public'),
];

用法

$asset = new Creode\LaravelAssets\Models\Asset;

// You can get the asset location from disk using a path.
$asset->path;

// You can get the url property of the asset.
$asset->url;

自定义缩略图生成

ThumbnailGenerator允许注册自定义缩略图生成器来处理不同的资产类型。这种可扩展性确保您的应用程序可以轻松适应新的文件类型或特定的缩略图生成要求。

示例

以下是注册和使用自定义缩略图生成器的完整示例

namespace App\Generators;

use Creode\LaravelAssets\Generators\PDFThumbnailGenerator;

class EPSThumbnailGenerator implements ThumbnailGeneratorInterface
{
    /**
     * Generates a thumbnail url for an asset.
     */
    public function generateThumbnailUrl(Asset $asset): ?string {
        // Custom logic to generate a thumbnail for an EPS file.
    }

    /**
     * Gets the type of output this generator produces.
     */
    public function getOutputType(): string {
        return 'image'; // typically 'image' or 'icon'.
    }
}
// AppServiceProvider.php

namespace App\Providers;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // Add an EPS thumbnail generator.
        $generator = resolve('assets.thumbnail.factory');

        $generator->addGenerator('image/x-eps', function () {
            return new \App\Generators\EPSThumbnailGenerator();
        });
    }
}

通过如上所示集成自定义生成器,您的应用程序现在将响应不同资产类型和缩略图生成策略的需求,同时保持干净和模块化的架构。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

贡献

有关详细信息,请参阅CONTRIBUTING

安全漏洞

有关如何报告安全漏洞的详细信息,请参阅我们的安全策略

致谢

许可

MIT许可证(MIT)。有关更多信息,请参阅许可文件