(PECL imagick >= 3.3.0)
Description
public static ImagickKernel ImagickKernel::fromBuiltin ( string $kernelType, string $kernelString )
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");
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"
Returns:
Examples:
ImagickKernel::fromBuiltin()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | <?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(0, 0, $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 /2 , $height /2); $imagickDraw ->setFillColor( 'rgba(0, 0, 0, 0)' ); $imagickDraw ->setStrokeColor( 'white' ); $imagickDraw ->circle(0, 0, $radius - 1, 0); $imagickDraw ->setStrokeColor( 'black' ); $imagickDraw ->circle(0, 0, $radius , 0); $imagickDraw ->pop(); $canvasWidth = $width + (2 * $imageMargin ); $canvasHeight = $height + (2 * $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 , $canvasHeight , 0, 0); /* composite original text_layer onto shadow_layer */ $canvas ->compositeImage( $kernel , \Imagick::COMPOSITE_OVER, 0, 0); $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_DIAMOND, 2, false, false); ?> |
Please login to continue.