michaldoda/laravel-s3-thumbnail
Composer 安装命令:
composer require michaldoda/laravel-s3-thumbnail
包简介
Customizable thumbnail generator for Laravel. From s3 to local disk. Minimize size of your images!
README 文档
README
🔥 original photo was 1024x1024, 989.98 kB
By creating many media pages, I have worked out some solution. This package will help you to minimize S3 / Cloudfront costs (sometimes unexpected) and the amount of data transfer. It also helps SEO by optimizing the image size - yeah I tried that and Google Lighthouse likes that. 🎉
If your assets are not in terabytes, this package may be of help to you. Especially if you create small or medium-sized media sites.
You can configure your own thumbnails settings. Currently, the package supports resize, crop and quality. It is not much, but it is a good step for optimizing your website.
Installation
# Install package composer require michaldoda/laravel-s3-thumbnail # Publish configuration php artisan vendor:publish --tag=s3-thumbnail-config # (Optional) if storage has not been linked php artisan storage:link
Usage
# resources/article/some-view.blade.php {{ $article->yourImageModel->getThumbnailHtml('article_main') }} # it will produce <picture data-alt="Description"> <source srcset="/storage/thumbnails/pk.../bc9400.../w600.jpeg" media="(max-width: 600px)"> <img src="/storage/thumbnails/pk.../bc9400.../default.jpeg" alt="Description"> </picture>
# app/Models/YourImageModel.php use MichalDoda\LaravelS3Thumbnail\ThumbnailInterface; use MichalDoda\LaravelS3Thumbnail\ThumbnailTrait; class YourImageModel extends Model implements ThumbnailInterface { use ThumbnailTrait; public function getS3ImagePath(): string { return $this->path; } public function getImageAltDescription(): ?string { return $this->alt; } }
# config/s3-thumbnail.php 'thumbnails' => [ 'article_main' => [ [ 'max_width' => 'default', 'quality' => 50, 'filters' => [ 'resize' => [ 'width' => 550, ], ], ], [ 'max_width' => 600, 'quality' => 50, 'filters' => [ 'resize' => [ 'width' => 350, ], ], ], // ... ], ]
Configuration
/** * It is a default Laravel local disk name. * If you are using different disk for local purpose then please update the value. */ 'local_disk' => 'local', /** * It is a default Laravel s3 disk name. * If you are using different disk for s3 file system then please update the value. */ 's3_disk' => 's3', /** * It is a default Laravel public disk name. * If you are using different disk for public purpose then please update the value. */ 'public_disk' => 'public', /** * It will create directory ./storage/app/public/thumbnails. * There will be placed all thumbnails generated by the package. * If you already use one of the path below then please update the value. * ./storage/app/public/thumbnails * ./public/storage/thumbnails */ 'public_path' => 'thumbnails', /** * It will create directory ./storage/app/originals. * There will be placed all images retrieved from AWS S3 disk. * If you already use path ./storage/app/originals then please update the value. */ 'originals_path' => 'originals', /** * Default format for thumbnails. * Available options: webp, jpeg */ 'default_format' => 'webp', /** * Default quality for thumbnails. * It will be used only if single thumbnail configuration does not have own value. */ 'default_quality' => 80, /** * Thumbnails configuration. */ 'thumbnails' => [ /** * Reduce image quality to 70% for all screens */ 'article_main' => [ [ 'max_width' => 'default', 'quality' => 70, 'filters' => [], ] ], /** * Reduce image quality to 70% for screens viewport > 480px * Reduce image quality to 50% for screens viewport <= 480px */ 'article_main_another' => [ [ 'max_width' => 'default', 'quality' => 70, 'filters' => [], ], [ 'max_width' => 480, 'quality' => 50, 'filters' => [], ], ], /** * Reduce image quality to 70% for all screens * Resize to width 550px */ 'article_suggestions1' => [ [ 'max_width' => 'default', 'quality' => 70, 'filters' => [ 'resize' => [ 'width' => 550, ], ], ], ], /** * Reduce image quality to 70% for all screens * Resize to width 650 * Crop 550x400 */ 'article_suggestions2' => [ [ 'max_width' => 'default', 'quality' => 70, 'filters' => [ 'resize' => [ 'width' => 650, ], 'crop' => [ 'width' => 550, 'height' => 400, ], ], ], ], ]
Testing
composer test
License
This package is open-sourced software licensed under the MIT License.
michaldoda/laravel-s3-thumbnail 适用场景与选型建议
michaldoda/laravel-s3-thumbnail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「s3」 「thumbnail」 「laravel」 「s3 thumbnails」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 michaldoda/laravel-s3-thumbnail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 michaldoda/laravel-s3-thumbnail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 michaldoda/laravel-s3-thumbnail 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
It is a easy and simple PHP image cropper and cache thumb manager
Thumbnails for videos
A PHP library for fetching thumbnails from a URL
A Gokaru storage & thumbnail server PHP client
A simple but effective command-line tool for generating thumbnails of a video, and corresponding VTT file, for use within JW Player to allow for toolbar video preview.
Official PHP integration for Optidash - AI-powered image optimization and processing API. We will drastically speed-up your websites and save you money on bandwidth and storage.
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-06