manticorp/image

PHP 中用于图像层混合的图像库

dev-master 2016-02-14 00:28 UTC

This package is not auto-updated.

Last update: 2024-09-24 20:22:38 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Manticorp\Image

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

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

例如,在我的 i7 电脑上使用 GD 图像库,16GB 内存,混合两个 500px 的正方形图像需要超过 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
  • DSTatop
  • DSTin
  • DSTout
  • DSTover
  • 排除
  • 硬光
  • 硬混合
  • 色调
  • 内部
  • 变亮
  • 变亮强度
  • 较亮颜色
  • 线性减淡
  • 线性加深
  • 线性光
  • 发光
  • 亮度
  • 数学
  • 减法
  • 减 DST
  • 减 Src
  • 调制
  • 模加
  • 模减
  • 乘法
  • 正常
  • 外部
  • 覆盖
  • 叠加
  • 顶光
  • 点光
  • 替换
  • 饱和
  • 饱和度
  • 屏幕
  • 柔光
  • Src
  • SrcAtop
  • SrcIn
  • SrcOut
  • SrcOver
  • 减去
  • 阈值
  • 未定义
  • 鲜艳光
  • 异或