承接 svenk/laravel-base64-images 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

svenk/laravel-base64-images

Composer 安装命令:

composer require svenk/laravel-base64-images

包简介

Simply store base64 images in laravel

README 文档

README

Simply store and delete base64 images in Laravel.

Installation

  1. Install the package via Composer:

    composer require svenk/laravel-base64-images
  2. Publish the configuration file:

    php artisan vendor:publish --tag=config
  3. Add the service provider and alias (if not using package auto-discovery):

    Open config/app.php and add the following to the providers array:

    SvenK\LaravelBase64Images\Base64ImagesServiceProvider::class,

    Add the following to the aliases array:

    'Base64ImageHelper' => SvenK\LaravelBase64Images\Facades\Base64ImageHelper::class,

Configuration

The configuration file config/base64images.php will be published to your application. You can customize the following settings:

return [
    'scaling' => env('BASE64IMAGES_SCALING', null),
    'quality' => env('BASE64IMAGES_QUALITY', 80),
];
  • scaling: The scaling factor for the images.
  • quality: The quality of the webp images (0-100).

Usage

Storing an Image

To store a base64 encoded image:

use SvenK\LaravelBase64Images\Facades\Base64ImageHelper;

$base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...'; // Your base64 encoded image string
$path = 'images'; // The directory where the image will be stored
$storedImagePath = Base64ImageHelper::store($base64Image, $path);

echo $storedImagePath; // Outputs the stored image path

Deleting an Image

To delete an image from storage:

use SvenK\LaravelBase64Images\Facades\Base64ImageHelper;

$imagePath = '/storage/images/your-image.webp';
$isDeleted = Base64ImageHelper::delete($imagePath);

if ($isDeleted) {
    echo 'Image deleted successfully.';
} else {
    echo 'Failed to delete image.';
}

What It Does

This package provides a helper class to easily store and delete base64 encoded images in Laravel.

  • Store: Converts a base64 encoded image to a webp format and saves it to the specified directory. The stored image path is returned.
  • Delete: Deletes an image from the specified path.

The helper class utilizes the Intervention Image package for image processing and Laravel's Storage facade for file storage operations.

License

This package is open-source software licensed under the MIT license.

Author

  • svenk2002

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-07-27