Rechercher une fonction PHP

ImagickKernel::fromBuiltIn

(PECL imagick >= 3.3.0)

ImagickKernel::fromBuiltInDescription

Description

public static ImagickKernel::fromBuiltin ( int $kernelType , string $kernelString ) : ImagickKernel

Create a kernel from a builtin in kernel. See http://www.imagemagick.org/Usage/morphology/#kernel for examples. Currently the 'rotation' symbols are not supported. Example: $diamondKernel = ImagickKernel::fromBuiltIn(\Imagick::KERNEL_DIAMOND, "2");

PHP: ImagickKernel::fromBuiltIn - Manual Home of Manuel PHP  Contents Haut

Parameters

kerneltype

The type of kernel to build e.g. \Imagick::KERNEL_DIAMOND

kernelString

A string that describes the parameters e.g. "4,2.5"

PHP: ImagickKernel::fromBuiltIn - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 ImagickKernel::fromBuiltin()

<?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 
createFromBuiltin($kernelType$kernelFirstTerm$kernelSecondTerm$kernelThirdTerm) {
    
$string '';

    if (
$kernelFirstTerm != false && strlen(trim($kernelFirstTerm)) != 0) {
        
$string .= $kernelFirstTerm;

        if (
$kernelSecondTerm != false && strlen(trim($kernelSecondTerm)) != 0) {
            
$string .= ','.$kernelSecondTerm;
            if (
$kernelThirdTerm != false && strlen(trim($kernelThirdTerm)) != 0) {
                
$string .= ','.$kernelThirdTerm;
            }
        }
    }

    
$kernel ImagickKernel::fromBuiltIn(
        
$kernelType,
        
$string
    
);

    return 
$kernel;
}
    
function 
fromBuiltin($kernelType$kernelFirstTerm$kernelSecondTerm$kernelThirdTerm) {
    
$diamondKernel createFromBuiltin($kernelType$kernelFirstTerm$kernelSecondTerm$kernelThirdTerm);
    
$imagick renderKernel($diamondKernel);

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

fromBuiltin(\Imagick::KERNEL_DIAMOND2falsefalse);


?>

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-imagickkernel.frombuiltin.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut