aquinoaldair/storage-image

Easy images storage for Laravel

2.0 2021-10-24 17:36 UTC

This package is auto-updated.

Last update: 2024-10-24 23:47:45 UTC


README

Latest Version on Packagist Build Status

Store Image for Laravel

Laravel library for easy store images in public storage.

Installation

You can install the package via composer:

composer require aquinoaldair/storage-image

Usage

use AquinoAldair\StorageImage\StorageImage;

Store from Base64

$image = "data:image/png;base64.....";

//store image with random 20 character name in Storage disk public (storage/app/public/customFolder) 
$file_name = StorageImage::FromBase64($image)->store("custom_folder");

echo $file_name; // "custom_folder/jqmix7a1l6masdGasd7S.jpg"

Store from FormData

$image = request()->image;

$file_name = StorageImage::FromFormData($image)->store("custom_folder");

Store from URL

$url = "https://homepages.cae.wisc.edu/~ece533/images/airplane.png";

$file_name = StorageImage::FromURL($url)->store("custom_folder");

Return only string

$url = "https://homepages.cae.wisc.edu/~ece533/images/airplane.png";

$file_name = StorageImage::FromString($url)->store("custom_folder");

echo $file_name; // "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"

Implement your own storage method

<?php

namespace AquinoAldair\StorageImage\Strategies;

use AquinoAldair\StorageImage\Contract\Image;

class MyCustomClass implements Image
{
     protected $file;
     
     public function __construct($file)
     {
         $this->file = $file;
     }
    public function store($folder = null)
    {
        // do something
    }
}
$image = "something";

StorageImage::make(new MyCustomClass($image))->store("custom_folder");

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT