imp*_*335 15 php laravel php-imagine laravel-5
我有以下内容:
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 = null, $mask = null)
{
$mode = ImageInterface::THUMBNAIL_OUTBOUND;
$size = new Box($width, $height);
$postfix = $postfix ? $postfix : 'thumb';
$thumbnail = Imagine::open("{$path}/{$filename}.{$extension}")->thumbnail($size, $mode);
if ($mask) {
$mask = Imagine::open('../public/images/masks/bubble-splash.png');
$thumbnail->applyMask($mask);
}
$destination = "{$filename}" . "." . $postfix . "." . "{$extension}";
$thumbnail->save("{$path}/{$destination}");
return $destination;
}
}
Run Code Online (Sandbox Code Playgroud)
它按预期保存图像,但不将蒙版应用于缩略图.
我哪里错了(我使用的是Laravel 5)?
此外,当脚本运行时,它需要大约1分钟才能完成,因此它正在执行某些操作但图像仍然在未应用蒙版的情况下输出.
最后我想我会用这些家伙 https://www.imgix.com/
结果白色透明度是 Imagine 中选择的遮罩逻辑。
https://github.com/avalanche123/Imagine/pull/449#issuecomment-127516157
这很可能是 Imagine 库中的一个错误。我发现了以下内容:
我无法使 GD\Image::applyMask() 按照http://www.slideshare.net/avalanche123/introduction-toimagine中的反射示例中所述工作,因此我做了一些修复。
- 它仍然仅支持 RGB 调色板作为遮罩,但现在考虑颜色之间的平均值。
- 如果透明度小于 0.5,它确实会改变图像。
来自https://github.com/avalanche123/Imagine/pull/449
相关修复尚未提交:
https://github.com/kasuparu/Imagine/commit/66a36652c76f9b5ff640f465d8f970c563841ae6
我尝试了固定代码,它似乎有效,除了遮罩(从我的角度来看)向后应用,保留黑色部分并丢弃白色部分。我在拉取请求中评论了这个问题。
作为参考,这是正在执行的修复:
使用 $blackAmount:

我使用 $whiteAmount 修复了这个问题:

| 归档时间: |
|
| 查看次数: |
1109 次 |
| 最近记录: |