nijwel / image-upload
Image upload package for Laravel
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.2
- laravel/framework: ^10.10
- laravel/sanctum: ^3.3
- laravel/tinker: ^2.8
- laravel/ui: ^4.2
- pusher/pusher-php-server: ^7.2
Requires (Dev)
- fakerphp/faker: ^1.9.1
- laravel/pint: ^1.0
- laravel/sail: ^1.18
- mockery/mockery: ^1.4.4
- nunomaduro/collision: ^7.0
- phpunit/phpunit: ^10.1
- spatie/laravel-ignition: ^2.0
README
A simple and flexible PHP package for handling image uploads, resizing, and management.
Features
- Upload images with support for multiple formats (JPEG, PNG, GIF, WEBP).
- Resize images while maintaining aspect ratio.
- Save images with dynamic filenames and custom paths.
Installation
You can install the nijwel/image-upload
package via Composer. Run the following command in your project directory:
composer require nijwel/image-upload
Configuration
No configuration is required to start using the package. However, you can customize paths and image dimensions as needed.
Usage
Basic Example
Here’s a simple example of how to use the package to upload and resize an image:
For v1.0.0
use Nijwel\ImageUpload\ImageUpload; $image = $request->input('image'); // Input image. $newImageName = 'my_image'; // IF you want to rename image (Also you can send null value) . $width = 200; // Desired width, (if you want to original image width pass value 0 or null). $height = null; // Desired height (null means maintain aspect ratio , You can handle manually) $path = 'backend/assets/images/'; // Directory to save the image // Just call in your method // Upload an image imageUpload($image, $width, $height, $path ,$newImageName ); // Upload a file $filePath = fileUpload($file, 'custom/path', 'newFileName');
For v^1.0
// Just call in your method for version v^1.0 use ImageUpload; // Upload an image $imagePath = ImageUpload::imageUpload($file, 300, 300, 'custom/path', 'newImageName'); // Upload a file $filePath = ImageUpload::fileUpload($file, 'custom/path', 'newFileName');
Methods v1.0.0
imageUpload($file, $newImageName = null, $width = null, $height = null, $path = 'images/')
Methods v^1.0
ImageUpload::imageUpload($file, $newImageName = null, $width = null, $height = null, $path = 'images/')
Uploads and resizes the image.
- file: Path to the original image file.
- newImageName: Name for the image (optional, a unique ID is used if not provided).
- width: Width for the resized image (optional).
- height: Height for the resized image (optional). If null or 0, the aspect ratio is maintained.
- path: Directory path to save the resized image (optional).
Error Handling
Ensure that the provided image path is correct and that the directory has appropriate write permissions. The package will throw exceptions for unsupported image types or invalid paths.
Contributing
If you'd like to contribute to the development of this package, please follow these steps:
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Push your branch and submit a pull request.
License
This package is licensed under the MIT License. See the LICENSE file for more details.
Contact
For any issues or questions, please open an issue on the repository or contact nijwel09@gmail.com
You can visit this repository : https://github.com/nijwel/image-upload.git