PHP code example of michelmelo / michelangelo

1. Go to this page and download the library: Download michelmelo/michelangelo 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/ */

    

michelmelo / michelangelo example snippets


use Michelmelo\Michelangelo\Michelangelo;

public function store(Request $request, Michelangelo $michelangelo)
{
    // ...

    // store original image in storage
    $article->image = $request->image->store('images');

    // optimize original image to desired dimensions
    $michelangelo->optimize($article->image, ['news', 'news_cover']);

    // ...
}

use Michelmelo\Michelangelo\Michelangelo;

public function update(Request $request, Article $article, Michelangelo $michelangelo)
{
    // ...

    if ($request->hasFile('image')) {

        // delete original image from storage
        Storage::delete($article->image);

        // delete all optimized images for old image
        $michelangelo->drop($article->image, ['news', 'news_cover']);

        // save new original image to storage and retrieve the path
        $article->image = $request->image->store('images');

        // optimize new original image
        $michelangelo->optimize($article->image, ['news', 'news_cover']);
    }

    // ...
}

use Michelmelo\Michelangelo\Michelangelo;


public function destroy(Article $article, Michelangelo $michelangelo)
{
    // ...

    // delete original image
    Storage::delete($article->image);

    // delete optimized images
    $michelangelo->purge($article->image);

    // delete record from database
    $article->delete();

    // ...
}
bash
php artisan vendor:publish --provider="Michelmelo\Michelangelo\ServiceProvider" --tag=config
blade
<image src="{{ Michelangelo::get($article->image, 'news') }}" />