如何使用图像处理库 Glide with plain PHP
How to use image manipulation library Glide with plain PHP
我正在为我的一个项目尝试使用 PHP Glide 图像处理库。我遵循了他们在此处给出的文档 - http://glide.thephpleague.com/1.0/simple-example/ 。
我创建了一个 "routes.php"。这是我的代码。
<?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' 的文件夹中,文件夹结构如下 -
因此,根据文档和我的理解,当我通过浏览器执行 "routes.php" 文件时,它应该 return 我在代码中硬编码的图像 URL。但是,我遇到了异常。
异常 -
PHP 致命错误:/var/www/testing/glide/vendor/league/glide/src/Server 中的消息 'Could not find the image img/users/source/1.jpg
.' 未捕获异常 'League\Glide\Filesystem\FileNotFoundException'。php:465\nStack 跟踪:\n# 0 /var/www/testing/glide/vendor/league/glide/src/Server.php(433): League\Glide\Server->makeImage('img/users/sourc...', 数组)\n#1 /var/www/testing/glide/routes.php(16 ): League\Glide\Server->outputImage('img/users/sourc...', Array)\n#2 {main}\n throw in /var/www/testing/glide/vendor/league/glide/src/Server.php on line 465
需要了解如何使用此滑行。
在要求旁边添加:
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 图像处理库。我遵循了他们在此处给出的文档 - http://glide.thephpleague.com/1.0/simple-example/ 。
我创建了一个 "routes.php"。这是我的代码。
<?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' 的文件夹中,文件夹结构如下 -
因此,根据文档和我的理解,当我通过浏览器执行 "routes.php" 文件时,它应该 return 我在代码中硬编码的图像 URL。但是,我遇到了异常。
异常 -
PHP 致命错误:/var/www/testing/glide/vendor/league/glide/src/Server 中的消息 'Could not find the image img/users/source/1.jpg
.' 未捕获异常 'League\Glide\Filesystem\FileNotFoundException'。php:465\nStack 跟踪:\n# 0 /var/www/testing/glide/vendor/league/glide/src/Server.php(433): League\Glide\Server->makeImage('img/users/sourc...', 数组)\n#1 /var/www/testing/glide/routes.php(16 ): League\Glide\Server->outputImage('img/users/sourc...', Array)\n#2 {main}\n throw in /var/www/testing/glide/vendor/league/glide/src/Server.php on line 465
需要了解如何使用此滑行。
在要求旁边添加:
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]);