定制 libaura/ext-aura 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

libaura/ext-aura

Composer 安装命令:

pie install libaura/ext-aura

包简介

PHP extension for the Aura color palette extraction library

README 文档

README

PHP extension for Aura, a library for extracting prominent color swatches from images.

Aura handles only the color processing. Reading and decoding the image is the caller's responsibility — the extension operates on raw RGBA pixel data provided as a binary string.

pipeline status Latest Release

Installation via PIE

PIE (PHP Installer for Extensions) is the recommended way to install this extension.

pie install libaura/ext-aura --with-aura=/path/to/libaura-prefix

--with-aura must point to a directory containing the pre-built libaura prefix (an include/ tree and lib/libaura.a). You can download a pre-built prefix from the libaura releases:

curl -fL -o libaura.tar.gz \
  "https://gitlab.com/api/v4/projects/libaura%2Faura/packages/generic/libaura/v1.0.1/libaura-linux-x86_64.tar.gz"
mkdir -p libaura-prefix && tar -xzf libaura.tar.gz -C libaura-prefix

pie install libaura/ext-aura --with-aura=$PWD/libaura-prefix

PIE will add extension=aura to your php.ini automatically.

Manual build

phpize
./configure --with-aura=/path/to/libaura-prefix
make

Load the built extension manually:

php -d extension=modules/aura.so your_script.php

Usage

The extension exposes five classes under the Aura\ namespace. The entry point is the static Palette::generate() method, which accepts raw RGBA pixel data as a binary string:

$palette = Aura\Palette::generate($imageContents);

if ($palette->vibrant !== null) {
    $r = $palette->vibrant->color->r;
    $g = $palette->vibrant->color->g;
    $b = $palette->vibrant->color->b;
}

An optional Aura\Config can be passed to control filtering behaviour:

$config = new Aura\Config(ignore_ineligible: true, filter: false);
$palette = Aura\Palette::generate($imageContents, $config);

Swatch roles

Palette exposes six nullable Swatch properties, not all of which may be present for a given image:

PropertyDescription
vibrantVivid, saturated color
vibrant_darkDark variant of vibrant
vibrant_lightLight variant of vibrant
mutedDesaturated color
muted_darkDark variant of muted
muted_lightLight variant of muted

Each Swatch has:

  • color: Aura\Colorr, g, b (0–255)
  • hsl: Aura\Hslh (0–360), s (0–1), l (0–1)
  • population: int — pixel count; indicates dominance
  • was_ineligible: bool — true if the swatch was only selected because no eligible candidate existed
  • is_text_white: bool — suggested text color for contrast

Preparing pixel data

generate() expects tightly-packed RGBA bytes — 4 bytes per pixel, no stride or padding. The length of the string must be a multiple of 4.

Using Imagick:

function imagickToRgba(string $path): string {
    $img = new Imagick($path);
    return pack('C*', ...$img->exportImagePixels(
        0, 0, $img->getImageWidth(), $img->getImageHeight(), 'RGBA', Imagick::PIXEL_CHAR
    ));
}

Using GD:

function gdToRgba(string $path): string {
    $img = imagecreatefromstring(file_get_contents($path));
    imagepalettetotruecolor($img);

    $out = '';
    for ($y = 0, $h = imagesy($img); $y < $h; $y++) {
        for ($x = 0, $w = imagesx($img); $x < $w; $x++) {
            $c = imagecolorat($img, $x, $y);
            $out .= pack('C4',
                ($c >> 16) & 0xFF,
                ($c >> 8)  & 0xFF,
                 $c        & 0xFF,
                (127 - (($c >> 24) & 0x7F)) * 2
            );
        }
    }

    imagedestroy($img);
    return $out;
}

Note: The GD pixel loop is slow on large images. For best performance, downsample images before passing them to generate().

Version constants

echo Aura\VERSION;        // e.g. "1.0.1"
echo Aura\VERSION_MAJOR;  // 1
echo Aura\VERSION_MINOR;  // 0
echo Aura\VERSION_PATCH;  // 1

Requirements

  • PHP 8.1+
  • Pre-built libaura prefix (linux/x86_64 tarball available from libaura releases)

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固