softrang/image-helper
Composer 安装命令:
composer require softrang/image-helper
包简介
A simple image upload, update, and delete helper for Laravel and PHP.
README 文档
README
A simple and developer-friendly helper for image upload, update, and delete in Laravel 12+, created by [Softrang](https://softrang.com).
- Upload images with optional resize (width & height)
- Update images (automatically deletes old image)
- Delete images safely from the public folder
- Optimize image quality and size (target 15–30 KB)
- Support for JPEG, PNG, GIF, WebP formats
1️⃣ Install via Composer
composer require softrang/image-helper
2️⃣ Upload Image
Upload an image with optional width and height. The function automatically resizes and optimizes the image.
$path = upload_image($request->file('image'), 'products', [ 'width' => 300, // Optional: Resize width 'height' => 300, // Optional: Resize height ]); // Save path to your database Product::create([ 'name' => $request->name, 'image' => $path ]);
3️⃣ Update Image
Update an image. This function automatically deletes the old image from the public folder and uploads the new one with optional resize.
$path = update_image($request->file('image'), $request->old_image, 'products', [ 'width' => 300, // Optional: Resize width 'height' => 300, // Optional: Resize height ]); // Update your database with new path $product->update([ 'image' => $path ]);
4️⃣ Delete Image
$image = $request->image; // Get image path from database delete_image($image);
5️⃣ Supported Image Formats
- jpg / jpeg
- png (supports transparency)
- gif
- webp (supports transparency)
6️⃣ Features
- ✅ Resize Images with optional width & height
- ✅ Quality Optimization to keep images between 15–30 KB
- ✅ Transparency Support for PNG & WebP
- ✅ Auto Delete Old Image on update
- ✅ Easy to Integrate in Laravel 12+ projects
- ✅ Standalone: No external packages required
7️⃣ Example Controller
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ProductController extends Controller { public function store(Request $request) { $path = upload_image($request->file('image'), 'products', [ 'width' => 300, 'height' => 300 ]); return response()->json(['uploaded' => $path]); } public function update(Request $request) { $path = update_image($request->file('image'), $request->old_image, 'products', [ 'width' => 300, 'height' => 300 ]); return response()->json(['updated' => $path]); } public function destroy(Request $request) { delete_image($request->image); return response()->json(['deleted' => true]); } }
8️⃣ Notes
- Automatically creates directories if they don’t exist
- Optimized for performance and small file size
- Easy to customize allowed file types
9️⃣ License
MIT License – free to use, modify, and distribute.
1️⃣0️⃣ How to Display the Image
After storing the image path in your database, you can display it in Blade like this:
@php
$image = $request->image; // or from your database column
@endphp
<img src="{{ asset($image) }}" alt="Uploaded Image">
Note:
- If your images are stored inside
public/uploads, and your database stores'uploads/filename.jpg', thenasset($image)will generate the correct URL. - If your images are stored inside subdirectories of
public/uploads(likepublic/uploads/subfolder/filename.jpg), and your database does not store the full path, thenasset($image)may not generate the correct URL. - Do not prepend
'uploads/'again if your database path already contains it.
softrang/image-helper 适用场景与选型建议
softrang/image-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 softrang/image-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 softrang/image-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-15