veyselaydogdu/laravel-base64-image
Composer 安装命令:
composer require veyselaydogdu/laravel-base64-image
包简介
A powerful Laravel package for handling base64 encoded images with automatic resizing, validation, and storage management
README 文档
README
A powerful Laravel package for handling base64 encoded images with automatic resizing, validation, and storage management. This package provides a simple and flexible way to save base64 encoded images to your Laravel application's storage system with advanced image processing capabilities.
Features
- 🖼️ Base64 Image Processing: Convert and save base64 encoded images
- 🔄 Image Resizing: Automatic image resizing with aspect ratio control
- 📏 Multiple Image Formats: Support for JPG, PNG, WebP, GIF, BMP, and SVG
- 🛡️ Validation: Built-in file size and type validation
- 💾 Flexible Storage: Support for multiple Laravel storage disks
- 🎨 Quality Control: Adjustable image quality settings
- 🧭 Auto Orientation: Automatic image orientation based on EXIF data
- 🔧 Configurable: Highly configurable via configuration file
- ✅ Well Tested: Comprehensive test coverage
- 📚 Laravel Integration: Native Laravel service provider and facade
Requirements
- PHP 8.0 or higher
- Laravel 9.0, 10.0, 11.0, or 12.0
- Intervention Image 3.0
Installation
You can install the package via Composer:
composer require veyselaydogdu/laravel-base64-image
The package will automatically register its service provider.
Publish Configuration
Publish the configuration file to customize the package settings:
php artisan vendor:publish --provider="VeyselAydogdu\LaravelBase64Image\Base64ImageServiceProvider" --tag="config"
This will create a config/base64-image.php file where you can customize the package settings.
Configuration
The configuration file allows you to customize various aspects of the package:
return [ // Default storage disk 'disk' => env('BASE64_IMAGE_DISK', 'public'), // Default upload location 'location' => env('BASE64_IMAGE_LOCATION', 'uploads'), // Maximum file size in KB 'max_size' => env('BASE64_IMAGE_MAX_SIZE', 5120), // 5MB // Supported image types 'supported_types' => [ 'jpg', 'jpeg', 'png', 'webp', 'gif', 'bmp', 'svg' ], // Default image quality (1-100) 'quality' => env('BASE64_IMAGE_QUALITY', 90), // Auto orient images based on EXIF data 'auto_orient' => env('BASE64_IMAGE_AUTO_ORIENT', true), // Filename generation settings 'filename' => [ 'length' => 45, 'max_attempts' => 5, ], ];
Environment Variables
You can set these environment variables in your .env file:
BASE64_IMAGE_DISK=public BASE64_IMAGE_LOCATION=uploads BASE64_IMAGE_MAX_SIZE=5120 BASE64_IMAGE_QUALITY=90 BASE64_IMAGE_AUTO_ORIENT=true
Usage
Basic Usage
use VeyselAydogdu\LaravelBase64Image\Facades\Base64Image; // Save a base64 image $result = Base64Image::save([ 'base64' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==' ]); if ($result['success']) { echo "Image saved to: " . $result['path']; echo "Image URL: " . $result['url']; }
Advanced Usage
use VeyselAydogdu\LaravelBase64Image\Facades\Base64Image; // Save with custom parameters $result = Base64Image::save([ 'base64' => $base64ImageData, 'disk' => 'public', 'location' => 'user-uploads', 'filename' => 'profile-picture', 'quality' => 85, 'width' => 800, 'height' => 600, 'maintain_aspect_ratio' => true ]);
Using the Manager Directly
use VeyselAydogdu\LaravelBase64Image\Base64ImageManager; $manager = new Base64ImageManager(); $result = $manager->save([ 'base64' => $base64ImageData, // ... other parameters ]);
Deleting Images
use VeyselAydogdu\LaravelBase64Image\Facades\Base64Image; // Delete an image $deleted = Base64Image::delete('uploads/image.jpg'); if ($deleted) { echo "Image deleted successfully"; }
Response Structure
The save method returns an array with the following structure:
[
'success' => true,
'path' => 'uploads/generated-filename.jpg',
'filename' => 'generated-filename.jpg',
'url' => 'https://your-app.com/storage/uploads/generated-filename.jpg',
'size' => 15432, // Size in bytes
'mime_type' => 'image/jpeg',
'extension' => 'jpg',
'dimensions' => [
'width' => 800,
'height' => 600
]
]
Available Parameters
Save Method Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
base64 |
string | required | Base64 encoded image data |
disk |
string | config value |
Storage disk to use |
location |
string | config value |
Directory to save the image |
filename |
string | generated |
Custom filename (without extension) |
quality |
int | config value |
Image quality (1-100) |
width |
int | null |
Target width for resizing |
height |
int | null |
Target height for resizing |
maintain_aspect_ratio |
bool | true |
Whether to maintain aspect ratio when resizing |
Error Handling
The package throws exceptions for various error conditions:
use VeyselAydogdu\LaravelBase64Image\Facades\Base64Image; try { $result = Base64Image::save([ 'base64' => $invalidBase64Data ]); } catch (\Exception $e) { // Handle the error echo "Error: " . $e->getMessage(); }
Common exceptions:
Base64 image data is requiredInvalid base64 image dataImage size exceeds maximum allowed sizeInvalid image dataUnsupported image type: {extension}Image processing failed: {reason}Failed to save image to storage
Testing
Run the package tests:
composer test
Run tests with coverage:
composer test-coverage
Security Vulnerabilities
If you discover a security vulnerability, please send an e-mail to Veysel Aydogdu via weysel.aydogdu@gmail.com. All security vulnerabilities will be promptly addressed.
Credits
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Made with ❤️ by Veysel Aydogdu
veyselaydogdu/laravel-base64-image 适用场景与选型建议
veyselaydogdu/laravel-base64-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「storage」 「upload」 「base64」 「resize」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 veyselaydogdu/laravel-base64-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 veyselaydogdu/laravel-base64-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 veyselaydogdu/laravel-base64-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-08