Rethink image manipulations with Glide

Rethink image manipulations with Glide

6074dbe5dfa361c9888a705f40a49af4?s=128

Jonathan Reinink

May 21, 2015
Tweet

Transcript

  1. 1.
  2. 8.
  3. 9.
  4. 10.

    It’s a good time for HTTP + PHP. Middleware and

    PSR-7 are changing how we build applications in PHP.
  5. 11.

    Only save your original images, not the manipulations. Then request

    different image sizes when they are needed.
  6. 15.

    Use Glide in an app, or create a separate image

    server. Offload image manipulations to a separate server on larger projects
  7. 17.

    get('/img/users/{id}', function ($id) { ! $server = ServerFactory::create([ 'source' =>

    'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage( 'users/'.$id.'.jpg', [ 'w' => 300, 'h' => 400 ] ); });
  8. 18.

    get('/img/{path}', function ($path) { ! $server = ServerFactory::create([ 'source' =>

    'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage($path, $_GET); });
  9. 19.

    get('/img/{path}', function (Request $request) { ! $server = ServerFactory::create([ 'source'

    => 'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage($request); });
  10. 24.

    $source = new Local('path/to/source'); $cache = new Local('path/to/cache'); ! $server

    = ServerFactory::create([ 'source' => new Filesystem($source), 'cache' => new Filesystem($cache), ]);
  11. 25.

    $client = S3Client::factory([ 'key' => 'your-key', 'secret' => 'your-secret', ]);

    ! $s3 = new AwsS3Adapter($client, 'your-bucket'); $cache = new Local('path/to/cache'); ! $server = ServerFactory::create([ 'source' => new Filesystem($s3), 'cache' => new Filesystem($cache), ]);
  12. 28.

    Prevent URL hacking by signing the image URLs. An important

    security step that should always be used in production.
  13. 29.

    $builder = UrlBuilderFactory::create( 'http://example.com', 'your-sign-key' ); ! // Generate a

    URL $url = $builder->getUrl('cat.jpg', ['w' => 500]); ! // Use the URL in your app echo '<img src="'.$url.'">';
  14. 34.
  15. 36.
  16. 45.
  17. 50.
  18. 54.