How to use image manipulation library Glide with plain PHP

耗尽温柔 提交于 2019-12-12 03:25:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!