如何使用图像处理库Glide与普通的PHP

问题描述 投票:0回答:1

我正在尝试将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'的文件夹中,文件夹结构是这样的 -

enter image description here

所以,根据doc和我的理解,当我通过浏览器执行“routes.php”文件时,它应该返回一个我在代码中硬编码的图像URL。但是,我得到了一个例外。

例外 -

PHP致命错误:未捕获的异常'League \ Glide \ Filesystem \ FileNotFoundException',消息'找不到图像img/users/source/1.jpg'。在/var/www/testing/glide/vendor/league/glide/src/Server.php:465 \ nStack trace:\ n #n / 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 image-manipulation php-glide
1个回答
0
投票

在require旁边添加:

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]);
© www.soinside.com 2019 - 2024. All rights reserved.