cjrasmussen/blendable-image

manticorp/image 的临时分支

dev-master 2021-04-19 16:00 UTC

This package is auto-updated.

Last update: 2024-09-20 00:11:47 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Manticorp\Image

一个提供类似 Photoshop 图层混合功能的图像库。

需要 PHP GD 图像库(非常慢)或 Imagick(快速!)之一

例如,在我的 i7 电脑上使用 GD 图像库,16GB 内存,混合两个 500 像素的正方形图像需要超过 4 秒。

这主要是因为 PHP 需要迭代每个像素。

安装

在 composer 中简单要求该包

composer require manticorp/image

用法

简单示例

<?php

$filename1 = 'baseimage.png';
$filename2 = 'topimage.png';

$base = new Manticorp\Image($filename1);
$top  = new Manticorp\Image($filename2);

$dim = 500;

$base->setDimensions($dim, $dim);
$top->setDimensions($base->getDimensions());

$bottom->setOutputFn('./temp/output.png');

$opacity = 1;
$fill    = 1; // Currently not implemented

$output = clone $bottom;
$output->blendWith($top, 'Overlay', $opacity, $fill);
echo $output->getImgTag(); // <img src='./temp/output.png'>

简单示例 2

<?php

$filename1 = 'baseimage.png';
$filename2 = 'topimage.png';

$modes = Manticorp\Image::getAvailableBlendingModes();

$base = new Manticorp\Image($filename1);
$top  = new Manticorp\Image($filename2);

$dim = 200;

$base->setDimensions($dim, $dim);
$top->setDimensions($base->getDimensions());

$opacity = 1;
$fill    = 1; // Currently not implemented

foreach($modes as $mode){
    $output = clone $base;
    $output->setOutputFn('./output-' . $mode . '.png');
    $output->blendWith($top, $mode, $opacity, $fill);
    echo "<div style='width:200px; height:300px; float:left;'><h3>".$mode."</h3>";
    echo $output->getImgTag(); // <img src='./output-{$mode}.png'>
    echo "</div>";
}

魔法方法

也提供了一组魔法方法

<?php
$filename1 = 'baseimage.png';
$filename2 = 'topimage.png';

$modes = Manticorp\Image::getAvailableBlendingModes();

$base = new Manticorp\Image($filename1);
$top  = new Manticorp\Image($filename2);

$dim = 200;

$base->setDimensions($dim, $dim);
$top->setDimensions($base->getDimensions());

$opacity = 1;
$fill    = 1; // Currently not implemented

$base->overlayWith($top, $opacity, $fill);

echo $base;

可用的混合模式

粗体 = 基于 Photoshop。

  • 添加
  • 覆盖
  • 混合
  • 模糊
  • 凹凸贴图
  • 更改蒙版
  • 清除
  • 颜色
  • 颜色减淡
  • 颜色增加
  • 着色
  • 复制
  • 复制黑色
  • 复制蓝色
  • 复制青色
  • 复制绿色
  • 复制洋红色
  • 复制不透明度
  • 复制红色
  • 复制黄色
  • 变暗
  • 变暗强度
  • 较暗的颜色
  • 默认
  • 差异
  • 置换
  • 溶解
  • 扭曲
  • 除法
  • 除 DST
  • 除 Src
  • DST
  • DST 在顶部
  • DST 内部
  • DST 外部
  • DST 覆盖
  • 排除
  • 硬光
  • 硬混合
  • 色调
  • 内部
  • 变亮
  • 变亮强度
  • 较亮的颜色
  • 线性减淡
  • 线性增加
  • 线性光
  • 发光
  • 亮度
  • 数学
  • 减法
  • 减 DST
  • 减 Src
  • 调节
  • 模数加
  • 模数减
  • 乘法
  • 正常
  • 外部
  • 覆盖
  • 叠加
  • 顶部光
  • 点光源
  • 加法
  • 替换
  • 饱和
  • 饱和度
  • 屏幕
  • 柔光
  • 源 在顶部
  • 源 内部
  • 源 外部
  • 源 覆盖
  • 减法
  • 阈值
  • 未定义
  • 亮光
  • 异或