PHP code example of makeabledk / laravel-cloud-images

1. Go to this page and download the library: Download makeabledk/laravel-cloud-images library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

makeabledk / laravel-cloud-images example snippets


'gcs' => [
    'driver' => 'gcs',
    'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
    'key_file_path' => env('GOOGLE_CLOUD_KEY_FILE', '/path/to/service-account.json'), 
    'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
],

php artisan vendor:publish --provider="Makeable\CloudImages\CloudImagesServiceProvider"
php artisan migrate
php artisan cloud-images:placeholders

$file = request()->file('image'); // assuming you uploaded a file through a form
$uploaded = \CloudImage::upload($file); // filename will be a hash of the uploaded file
$uploadedToPath = \CloudImage::upload($file, 'path/filename.jpg'); // optionally specify path and filename yourself
        
echo $uploaded->url; // imageserver url, eg: http://lh3.googleusercontent.com/...
echo $uploaded->path; // path in bucket

\CloudImage::delete('path/filename.jpg');

$image = \CloudImage::upload($file)->make();
// or ...
$image = new \Makeable\CloudImages\ImageFactory($url); 

$image->maxDimension(150)->get();

$image->crop(300, 100)->get(); // Crop from top
$image->cropCenter(300, 100)->get(); // Crop from center

$image->scale(300, 100)->get(); 

$image->blur(15)->get(); // Blur 15% 

$image->original()->param('fv')->get(); // This image will be flipped vertically

$image = \Makeable\CloudImages\Image::upload($file); // returns a persisted Image model instance (eloquent)

echo $image->path; // bucket path
echo $image->url; // image-serving url
echo $image->meta; // exif data 

class Product extends Eloquent
{
    use Makeable\CloudImages\HasImages;
}

Product::first()->images()->attach(Image::first());

$product = Product::first();
$images = $product->images; // In this example we assume a collection of a few images

$product->images()->moveBefore($images->get(2), $images->first());

class Product extends Eloquent
{
    use Makeable\CloudImages\HasImages;
}

// Always returns an Image instance - even if none uploaded
$image = Product::first()->image(); 

// Returns a url (string) or NULL if no image attached
$url =  $image->make()->cropCenter(500, 400)->get(); 

Product::first()->image('featured');
Product::first()->image('cover');

Product::first()->image('featured')->replaceWith(Image::upload($file));

class Product extends Eloquent
{
    use \Makeable\CloudImages\HasImages;
    
    public function setImageAttribute($file)
    {
        return $this->image()->replaceWith(Image::upload($file));
    }
}

Product::first()->image = request('image'); // replace image with an UploadedFile 'image'

public function store(Request $request)
{
    return Product::create(
        $request->validate([
            'image' => '

class Product extends Eloquent
{
    use \Makeable\CloudImages\HasImages;
    
    protected $useImageClass = ProductImage::class;
}

class ProductImage extends \Makeable\CloudImages\Image
{
    public function getSquareAttribute()
    {
        return $this->make()->cropCenter(500, 500)->get();
    }

    public function getWideAttribute()
    {
        return $this->make()->cropCenter(1200, 400)->get();
    }
}

echo Product::first()->image()->square; // single image usage
echo Product::first()->images->first()->wide; // multiple images usage

class ProductImage extends Image
{
    protected $appends = ['square', 'wide'];
    
    // ...
}

// Returns collection of ImageFactory instances width contiously smaller images
Product::first()->image()->make()->original()->responsive()->get(); 

// Returns contents of the html srcset attribute
Product::first()->image()->make()->original()->responsive()->getSrcSet(); 

// Returns an array containing src, srcet and width attribute - especially useful for API responses
Product::first()->image()->make()->original()->responsive()->toArray(); 

// Returns <img> element with srcset attribute
Product::first()->image()->make()->original()->responsive()->toHtml(); 
(string) Product::first()->image()->make()->original()->responsive(); 

Product::first()->image()->make()->crop(500, 400)->param('fv')->responsive()->get(); 
bash
php artisan vendor:publish --provider="Makeable\CloudImages\CloudImagesServiceProvider"
php artisan migrate
bash
php artisan cloud-images:cleanup