mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-26 01:42:09 +01:00
200 lines
5.7 KiB
XML
200 lines
5.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 1534707f677267513659e57f530ed5f4cf08f924 Maintainer: Fan2Shrek Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<refentry xml:id="imagickkernel.frommatrix" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>ImagickKernel::fromMatrix</refname>
|
|
<refpurpose>Créer un noyau à partir d'une matrice 2D de valeurs</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier> <modifier>static</modifier> <type>ImagickKernel</type><methodname>ImagickKernel::fromMatrix</methodname>
|
|
<methodparam><type>array</type><parameter>matrix</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>origin</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Créer un noyau à partir d'une matrice 2D de valeurs. Chaque valeur doit être soit un flottant
|
|
(si l'élément doit être utilisé) ou 'false' si l'élément doit être ignoré. Pour
|
|
les matrices qui ont des tailles impaires dans les deux dimensions, le pixel d'origine sera par défaut
|
|
au centre du noyau. Pour toutes les autres tailles de noyau, le pixel d'origine doit être spécifié.
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Une matrice (c'est-à-dire un tableau 2D) de valeurs qui définissent le noyau. Chaque élément doit être soit une valeur flottante, ou FALSE si cet élément ne doit pas être utilisé par le noyau.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Quel élément du noyau doit être utilisé comme pixel d'origine. Par exemple, pour une matrice 3x3 spécifiant l'origine comme [2, 2] spécifierait que l'élément en bas à droite devrait être le pixel d'origine.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
L'objet ImagickKernel généré.
|
|
</para>
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title> <function>ImagickKernel::fromMatrix</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?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);
|
|
|
|
/* créer une ombre portée sur sa propre couche */
|
|
$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 createFromMatrix() {
|
|
$matrix = [
|
|
[0.5, 0, 0.2],
|
|
[0, 1, 0],
|
|
[0.9, 0, false],
|
|
];
|
|
|
|
$kernel = \ImagickKernel::fromMatrix($matrix);
|
|
|
|
return $kernel;
|
|
}
|
|
|
|
function fromMatrix() {
|
|
$kernel = createFromMatrix();
|
|
$imagick = renderKernel($kernel);
|
|
|
|
header("Content-Type: image/png");
|
|
echo $imagick->getImageBlob();
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|