我有以下内容:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine;
class UploadController extends Controller {
public function processImage($request) {
$file = $request->file('file');
$path = '/images';
$fileName = 'image.png';
if ($file) {
$file->move('../public' . $path, $fileName);
$gThumb = $this->createThumbnail(219, 300, '../public/images', 'image', 'png', 'thumb', true);
$pThumb = $this->createThumbnail(300, 300, '../public/images', 'image', 'png', 'pthumb');
return response()->json([
'gallery_thumbnail' => $path . '/' . $gThumb,
'upload_thumbnail' => $path . '/' . $pThumb
]);
}
}
function createThumbnail($height, $width, $path, $filename, $extension, $postfix = …Run Code Online (Sandbox Code Playgroud) 使用Laravel并尝试使用Imagine处理图像上传.
问题是我收到错误说明:
Imagine \ Exception \ RuntimeException
Imagick not installed
Open: /Applications/MAMP/htdocs/laravelcms/vendor/imagine/imagine/lib/Imagine/Imagick/Imagine.php
{
/**
* @throws RuntimeException
*/
public function __construct()
{
if (!class_exists('Imagick')) {
throw new RuntimeException('Imagick not installed');
}
Run Code Online (Sandbox Code Playgroud)
我按照本指南,正确创建了所有文件夹和文件等,如下所述:
http://creolab.hr/2013/07/image-manipulation-in-laravel-4-with-imagine/
我还检查了Imagick文件夹,所有文件等都在正确的位置.
有帮助吗?
谢谢,克雷格.
I am using imagine library to create thumbnails for images. It is as simple as this.
$size = new \Imagine\Image\Box(240, 180);
$imagine->open($source_path)->thumbnail($size, 'inset')->save($target_path);
Run Code Online (Sandbox Code Playgroud)
该库提供两种模式:插入和出站.在插入模式下,图像调整大小但不填充缩略图大小.所以我需要填充它来填充目标大小.有没有一种简单的方法来使用库函数?
我在yii2中得到了这段代码:
Image::thumbnail($path, 100, 100)->save($thumbnail, ['quality' => 50]);
Run Code Online (Sandbox Code Playgroud)
我认为它将调整保持纵横比的原始图像的大小.但它只是创造了一个盒子......有什么可能是错的?
我使用的是 Symfony 2.3.*,当我使用 LiipImagineBundle 时,我在 app/logs/dev.log 中收到此错误。
request.CRITICAL: Uncaught PHP Exception Imagine\Exception\InvalidArgumentException: "png_compression_level option should be an integer from 0 to 9" at /vendor/imagine/imagine/lib/Imagine/Gd/Image.php line 535 {"exception":"[object] (Imagine\\Exception\\InvalidArgumentException: png_compression_level option should be an integer from 0 to 9 at /vendor/imagine/imagine/lib/Imagine/Gd/Image.php:535)"} []
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?谢谢
这是我的配置
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
standard:
quality: 200
filters:
thumbnail: { size: [400, 300], mode: outbound }
Run Code Online (Sandbox Code Playgroud)