ImagickKernel::fromMatrix

(PECL imagick >= 3.3.0)

ImagickKernel::fromMatrixDescription

Beschreibung

public static ImagickKernel::fromMatrix(array $matrix, array $origin = ?): ImagickKernel

Create a kernel from an 2d matrix of values. Each value should either be a float (if the element should be used) or 'false' if the element should be skipped. For matrices that are odd sizes in both dimensions the origin pixel will default to the centre of the kernel. For all other kernel sizes the origin pixel must be specified.

Parameter-Liste

array

A matrix (i.e. 2d array) of values that define the kernel. Each element should be either a float value, or FALSE if that element shouldn't be used by the kernel.

array

Which element of the kernel should be used as the origin pixel. e.g. For a 3x3 matrix specifying the origin as [2, 2] would specify that the bottom right element should be the origin pixel.

Rückgabewerte

The generated ImagickKernel.

Beispiele

Beispiel #1 ImagickKernel::fromMatrix()

<?php

function renderKernel(ImagickKernel $imagickKernel) {
    
$matrix $imagickKernel->getMatrix();
    
    
$imageMargin 20;
    
    
$tileSize 20;
    
$tileSpace 4;
    
$shadowSigma 4;
    
$shadowDropX 20;
    
$shadowDropY 0;

    
$radius = ($tileSize 2) * 0.9;
    
    
$rows count($matrix);
    
$columns count($matrix[0]);
 
    
$imagickDraw = new \ImagickDraw();

    
$imagickDraw->setFillColor('#afafaf');
    
$imagickDraw->setStrokeColor('none');
    
    
$imagickDraw->translate($imageMargin$imageMargin);
    
$imagickDraw->push();

    
ksort($matrix);
    
    foreach (
$matrix as $row) {
        
ksort($row);
        
$imagickDraw->push();
        foreach (
$row as $cell) {
            if (
$cell !== false) {
                
$color intval(255 $cell);
                
$colorString sprintf("rgb(%f, %f, %f)"$color$color$color);
                
$imagickDraw->setFillColor($colorString);
                
$imagickDraw->rectangle(00$tileSize$tileSize);
            }
            
$imagickDraw->translate(($tileSize $tileSpace), 0);
        }
        
$imagickDraw->pop();
        
$imagickDraw->translate(0, ($tileSize $tileSpace));
    }

    
$imagickDraw->pop();

    
$width = ($columns $tileSize) + (($columns 1) * $tileSpace);
    
$height = ($rows $tileSize) + (($rows 1) * $tileSpace);

    
$imagickDraw->push();
    
$imagickDraw->translate($width/$height/2);
    
$imagickDraw->setFillColor('rgba(0, 0, 0, 0)');
    
$imagickDraw->setStrokeColor('white');
    
$imagickDraw->circle(00$radius 10);
    
$imagickDraw->setStrokeColor('black');
    
$imagickDraw->circle(00$radius0);
    
$imagickDraw->pop();

    
$canvasWidth $width + ($imageMargin); 
    
$canvasHeight $height + ($imageMargin);

    
$kernel = new \Imagick();
    
$kernel->newPseudoImage(
        
$canvasWidth,
        
$canvasHeight,
        
'canvas:none'
    
);

    
$kernel->setImageFormat('png');
    
$kernel->drawImage($imagickDraw);
 
    
/* create drop shadow on it's own layer */
    
$canvas $kernel->clone();
    
$canvas->setImageBackgroundColor(new \ImagickPixel('rgb(0, 0, 0)'));
    
$canvas->shadowImage(100$shadowSigma$shadowDropX$shadowDropY);

    
$canvas->setImagePage($canvasWidth$canvasHeight, -5, -5);
    
$canvas->cropImage($canvasWidth$canvasHeight00);
    
    
/* composite original text_layer onto shadow_layer */
    
$canvas->compositeImage($kernel, \Imagick::COMPOSITE_OVER00);
    
$canvas->setImageFormat('png');

    return 
$canvas;
}

function 
createFromMatrix() {
    
$matrix = [
        [
0.500.2],
        [
010],
        [
0.90false],
    ];

    
$kernel = \ImagickKernel::fromMatrix($matrix);

    return 
$kernel;
}
    
function 
fromMatrix() {
    
$kernel createFromMatrix();
    
$imagick renderKernel($kernel);

    
header("Content-Type: image/png");
    echo 
$imagick->getImageBlob();
}

?>

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

SEO-URLs und MySQL

Thank you for sharing

Geschrieben von thunder332 am 08.04.2025 05:44:21
Forum: SQL / Datenbanken
SEO-URLs und MySQL

Sie können URL-Rewrite verwenden, um dynamische URLs (mit Datensatz-IDs) in statische, SEO-freundliche URLs umzuwandeln.​

Geschrieben von thunder332 am 08.04.2025 05:37:17
Forum: SQL / Datenbanken
AI Nude Tool—Make Deepnude & Deepfake for Free

Ein Thread voller Spam im Board IT-Security, genau mein Humor. :rofl:

Geschrieben von scatello am 05.04.2025 14:48:56
Forum: IT-Security
AI Nude Tool—Make Deepnude & Deepfake for Free

I've always been curious about numerology and your post answered so many questions! Destiny Matrix (https://destiny-matrix.cc/)​ has been my go- ...

Geschrieben von yxchen1994 am 05.04.2025 13:13:14
Forum: IT-Security