问题描述
我正在尝试为我的一个项目使用PHP Glide图像处理库.我已按照此处提供的文档进行操作- http://glide.thephpleague.com/1.0/simple-example/.
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/ .
我创建了一个"routes.php".这是我的代码.
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]);
我的图像位于名为"img"的文件夹中.文件夹结构是这样的-
My images are in folder called 'img' & folder structure is like this -
因此,根据文件&我的理解是,当我通过浏览器执行"routes.php"文件时,它应该返回一个图像URL,该URL已在代码中进行了硬编码.但是,我得到一个例外.
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.
例外-
PHP致命错误:消息为找不到图像img/users/source/1.jpg
"的未捕获异常'League \ Glide \ Filesystem \ FileNotFoundException'.在/var/www/testing/glide/vendor/league/glide/src/Server.php:465\n堆栈跟踪中:\ 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放在/var/www/testing/glide/vendor/league/glide/src/Server.php中在第465行
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.
推荐答案
将此添加到要求旁边:
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Glide\ServerFactory;
赞:
<?
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]);
这篇关于如何在纯PHP中使用图像处理库Glide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!