问题
I'm trying to use PHP Glide image manipulation library for one of my projects. I've followed their docs given at here - http://glide.thephpleague.com/1.0/simple-example/ .
I've created a "routes.php". Here is my code.
<?php
require 'vendor/autoload.php';
// Setup Glide server
$server = League\Glide\ServerFactory::create([
'source' => 'img/users/source',
'cache' => 'img/users/cache',
]);
// echo '<pre>';
// print_r($server);
// echo '</pre>';
// You could manually pass in the image path and manipulations options
//$server->outputImage('users/1.jpg', ['w' => 300, 'h' => 400]);
$server->outputImage('img/users/source/1.jpg', ['w' => 300, 'h' => 400]);
My images are in folder called 'img' & folder structure is like this -
So, according to the doc & my understanding when I execute "routes.php" file through the browser it should return me an image URL which I've hardcoded in the code. But, I'm getting an exception instead.
Exception -
PHP Fatal error: Uncaught exception 'League\Glide\Filesystem\FileNotFoundException' with message 'Could not find the image img/users/source/1.jpg.' in /var/www/testing/glide/vendor/league/glide/src/Server.php:465\nStack trace:\n#0 /var/www/testing/glide/vendor/league/glide/src/Server.php(433): League\Glide\Server->makeImage('img/users/sourc...', Array)\n#1 /var/www/testing/glide/routes.php(16): League\Glide\Server->outputImage('img/users/sourc...', Array)\n#2 {main}\n thrown in /var/www/testing/glide/vendor/league/glide/src/Server.php on line 465
Need some to understand how to work with this glide.
回答1:
Add this next to the require:
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Glide\ServerFactory;
Like this:
<?
require '../vendor/autoload.php';
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Glide\ServerFactory;
// Setup Glide server
$server = League\Glide\ServerFactory::create([
'source' => '../assets/img/source',
'cache' => '../assets/img/cache',
]);
// You could manually pass in the image path and manipulations options
$server->outputImage('01.jpg', ['w' => 300, 'h' => 400]);
来源:https://stackoverflow.com/questions/36527666/how-to-use-image-manipulation-library-glide-with-plain-php