Laravel library for easy store images in public storage.
You can install the package via composer:
composer require aquinoaldair/storage-image
use AquinoAldair\StorageImage\StorageImage;
$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"
$image = request()->image;
$file_name = StorageImage::FromFormData($image)->store("custom_folder");
$url = "https://homepages.cae.wisc.edu/~ece533/images/airplane.png";
$file_name = StorageImage::FromURL($url)->store("custom_folder");
$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"
<?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");
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.