哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

Imagick::sparseColorImage

(PECL imagick 2 >= 2.3.0, PECL imagick 3)

Imagick::sparseColorImageInterpolates colors

说明

public Imagick::sparseColorImage(int $SPARSE_METHOD, array $arguments, int $channel = Imagick::CHANNEL_DEFAULT): bool

Given the arguments array containing numeric values this method interpolates the colors found at those coordinates across the whole image using sparse_method. 此方法在Imagick基于ImageMagick 6.4.5以上版本编译时可用。

参数

SPARSE_METHOD

Refer to this list of sparse method constants

arguments

An array containing the coordinates. The array is in format array(1,1, 2,45)

channel

Provide any channel constant that is valid for your channel mode. To apply to more than one channel, combine channel constants using bitwise operators. 缺省为Imagick::CHANNEL_DEFAULT. 参考此 通道常数列表

返回值

成功时返回 true

错误/异常

错误时抛出 ImagickException。

范例

示例 #1 SPARSECOLORMETHOD_BARYCENTRIC Imagick::sparseColorImage()

<?php
    
function renderImageBarycentric2() {
        
$points = [
            [
0.300.10'red'],
            [
0.100.80'blue'],
            [
0.700.60'lime'],
            [
0.800.20'yellow'],
        ];
        
$imagick createGradientImage(
            
400400,
            
$points,
            \
Imagick::SPARSECOLORMETHOD_BARYCENTRIC
        
);
        
header("Content-Type: image/png");
        echo 
$imagick->getImageBlob();
    }

?>

示例 #2 SPARSECOLORMETHOD_BILINEAR Imagick::sparseColorImage()

<?php
    
function renderImageBilinear() {
        
$points = [[0.300.10'red'], [0.100.80'blue'], [0.700.60'lime'], [0.800.20'yellow'],];
        
$imagick createGradientImage(500500$points, \Imagick::SPARSECOLORMETHOD_BILINEAR);
        
header("Content-Type: image/png");
        echo 
$imagick->getImageBlob();
    }

?>

示例 #3 SPARSECOLORMETHOD_SPEPARDS Imagick::sparseColorImage()

<?php
    
function renderImageShepards() {
        
$points = [
            [
0.300.10'red'],
            [
0.100.80'blue'],
            [
0.700.60'lime'],
            [
0.800.20'yellow'],
        ];
        
$imagick createGradientImage(600600$points, \Imagick::SPARSECOLORMETHOD_SPEPARDS);
        
header("Content-Type: image/png");
        echo 
$imagick->getImageBlob();
    }

?>

示例 #4 SPARSECOLORMETHOD_VORONOI Imagick::sparseColorImage()

<?php
    
function renderImageVoronoi() {
        
$points = [
            [
0.300.10'red'],
            [
0.100.80'blue'],
            [
0.700.60'lime'],
            [
0.800.20'yellow'],
        ];
        
$imagick createGradientImage(500500$points, \Imagick::SPARSECOLORMETHOD_VORONOI);
        
header("Content-Type: image/png");
        echo 
$imagick->getImageBlob();
    }

?>

示例 #5 SPARSECOLORMETHOD_BARYCENTRIC Imagick::sparseColorImage()

<?php
    
function renderImageBarycentric() {
        
$points = [
            [
00'skyblue'],
            [-
11'skyblue'],
            [
11'black'],
        ];
        
$imagick createGradientImage(600200$points, \Imagick::SPARSECOLORMETHOD_BARYCENTRIC);
        
header("Content-Type: image/png");
        echo 
$imagick->getImageBlob();
    }

?>

示例 #6 createGradientImage is used by other examples. Imagick::sparseColorImage()

<?php
function createGradientImage($width$height$colorPoints$sparseMethod$absolute false) {

    
$imagick = new \Imagick();
    
$imagick->newImage($width$height"white");
    
$imagick->setImageFormat("png");

    
$barycentricPoints = array();

    foreach (
$colorPoints as $colorPoint) {

        if (
$absolute == true) {
            
$barycentricPoints[] = $colorPoint[0];
            
$barycentricPoints[] = $colorPoint[1];
        }
        else {
            
$barycentricPoints[] = $colorPoint[0] * $width;
            
$barycentricPoints[] = $colorPoint[1] * $height;
        }

        if (
is_string($colorPoint[2])) {
            
$imagickPixel = new \ImagickPixel($colorPoint[2]);
        }
        else if (
$colorPoint[2] instanceof \ImagickPixel) {
            
$imagickPixel $colorPoint[2];
        }
        else{
            
$errorMessage sprintf(
                
"Value %s is neither a string nor an ImagickPixel class. Cannot use as a color.",
                
$colorPoint[2]
            );

            throw new \
InvalidArgumentException(
                
$errorMessage
            
);
        }

        
$red $imagickPixel->getColorValue(\Imagick::COLOR_RED);
        
$green $imagickPixel->getColorValue(\Imagick::COLOR_GREEN);
        
$blue $imagickPixel->getColorValue(\Imagick::COLOR_BLUE);
        
$alpha $imagickPixel->getColorValue(\Imagick::COLOR_ALPHA);

        
$barycentricPoints[] = $red;
        
$barycentricPoints[] = $green;
        
$barycentricPoints[] = $blue;
        
$barycentricPoints[] = $alpha;
    }

    
$imagick->sparseColorImage($sparseMethod$barycentricPoints);

    return 
$imagick;
}

?>
打开 哈希空间 微信小程序中查看更佳