Skip to content

aquinoaldair/storage-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Easy images storage for Laravel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages