Componente di Elaborazione delle Immagini

Indirizzo del Progetto

https://github.com/Intervention/image

Installazione

composer require intervention/image

Utilizzo

Frammento della pagina di caricamento

  <form method="post" action="/user/img" enctype="multipart/form-data">
      <input type="file" name="file">
      <input type="submit" value="Invia">
  </form>

Crea app/controller/UserController.php

<?php
namespace app\controller;
use support\Request;
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;

class UserController
{
    public function img(Request $request)
    {
        $file = $request->file('file');
        if ($file && $file->isValid()) {
            $manager = new ImageManager(new Driver());
            $image = $manager->read($file)->scale(100, 100);
            return response($image->encode(), 200, ['Content-Type' => 'image/png']);
        }
        return response('file not found');
    }

}

Attenzione
Quanto sopra è l'uso per la versione v3

Contenuti Aggiuntivi

Visita https://image.intervention.io/v3