定制 donia-shaker/media-library 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

donia-shaker/media-library

Composer 安装命令:

composer require donia-shaker/media-library

包简介

README 文档

README

This package provides a set of functions for handling media files, including images, audio, video, and PDF files.

Features

  • Versatile Storage Options: Seamlessly store and manage your files in both public and private storage environments.
  • Image Conversion Made Easy: Effortlessly convert and store images in multiple formats to suit all your needs.
  • Automatic Thumbnail Generation: Instantly create and manage image thumbnails upon upload, saving you time and effort.
  • Universal File Storage: Store and organize any file type, including documents, videos, and audio files.
  • Soft Delete Support: Safeguard your data with soft delete functionality, allowing you to restore accidentally deleted files easily.
  • URL Generation: Instantly generate shareable URLs for your files, making it simple to share and access your stored content.
  • Image Upload Rules: Ensure optimal performance and quality with customizable image upload rules, including dimensions, size, and format restrictions.

Installation

To install the DoniaShaker\MediaLibrary package, follow these steps:

  1. Add the package to your Laravel project using Composer:

    composer require donia-shaker/media-library
  2. Publish the Database migrations and config to your project:

    php artisan vendor:publish --tag=media-library-migrations
    php artisan vendor:publish --tag=media-library-config
  3. If you wish to use a default format other than the default webp format, edit the following line in config/media-library.php

    default_image_format = 'webp' // <-- change this value
  4. Add ENV variables required by the package config

    MEDIA_USE_STORAGE=true|false
  5. Run the package's migrations to create the necessary database tables:

    php artisan migrate

Usage

Initialization

  1. use the package:
use DoniaShaker\MediaLibrary\MediaController;
  1. Call the Constructor
$media_controller =  new MediaController();
  1. in the following examples, the $format field can be null, thus using the default_image_format value defined from the config.

Save Image

This function saves an image file to the media library, generates a thumbnail, and associates it with the current model. Usage:

$media_controller->saveImage($model, $model_id, $file, $format);

Create Temporary Image

This function creates a temporary image file in the media library.

Usage:

$media_controller->saveTempImage($model, $model_id, $file);

Convert Temporary Image

This function converts a temporary image file to a normal image file in the media library, deletes the temporary file and record, and associates the new image with the current model.

Usage:

$media_controller->convertTempImage($model, $model_id, $media->id);

Delete Temporary Image

This function deletes a temporary image file and record from the media library.

Usage:

$media_controller->deleteTemp();

Save Audio File

This function saves an audio file to the media library and associates it with the current model.

Usage:

$media_controller->audio($model, $model_id, $file);

Save Video File

This function saves a video file to the media library and associates it with the current model. Usage:

$media_controller->video($model, $model_id, $file);

Save Document File

This function saves a document file to the media library and associates it with the current model. Usage:

$media_controller->uploadFile($model, $model_id, $file);

Media Object

Explanation of the media object properties:

  • id: The unique identifier of the media object.
  • model: The model associated with the media object (in this case, "slider").
  • format: The file format of the media object.
  • model_id: The ID of the associated model (in this case, 2).
  • order: The order of the media object (in case model has many media).
  • file_name: The unique file name of the media object.
  • has_thumb: Indicates whether the media object has a thumbnail (1 for true, 0 for false).
  • is_active: Indicates whether the media object is active (1 for true, 0 for false).
  • is_temp: Indicates whether the media object is temporary (1 for true, 0 for false).
  • deleted_at: The timestamp indicating when the media object was deleted (null if not deleted).
  • created_at: The timestamp indicating when the media object was created.
  • updated_at: The timestamp indicating when the media object was last updated.
  • url: The URL to access the original image file including temp.
  • thumb_url: The URL to access the thumbnail image file (if available).

The media object represents a media file stored in the media library. It contains various properties providing information about the file, such as its associated model, file format, URLs for accessing the image and thumbnail, and timestamps for creation and updates.

Rules

Square Image

This function saves a document file to the media library and associates it with the current model. It accepts the $file parameter, which represents the uploaded document file.

Usage:

use DoniaShaker\MediaLibrary\Rules\SquareImageRule;

'file' => [.., new  SquareImageRule],

Troubleshooting and Collaboration

If you encounter any issues or have any suggestions, please feel free to open an issue on GitHub.

donia-shaker/media-library 适用场景与选型建议

donia-shaker/media-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.24k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 donia-shaker/media-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 donia-shaker/media-library 我们能提供哪些服务?
定制开发 / 二次开发

基于 donia-shaker/media-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-21