-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathexamples.xml
More file actions
151 lines (139 loc) · 5.31 KB
/
examples.xml
File metadata and controls
151 lines (139 loc) · 5.31 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: yannick Status: ready -->
<!-- Reviewed: yes -->
<chapter xml:id="image.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<section xml:id="image.examples-png">
<title>Création d'une image PNG avec PHP</title>
<para>
<example>
<title>Création d'une image PNG avec PHP</title>
<programlisting role="php">
<![CDATA[
<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
?>
]]>
</programlisting>
</example>
Cet exemple doit être appelé depuis une page HTML avec une balise
image telle que : <literal><img src="button.php?text"></literal>.
Le script ci-dessus, <filename>button.php</filename>, prend la chaîne
<literal>"texte"</literal> et l'inscrit
sur le fond d'image appelé <literal>"images/button1.png"</literal>,
puis l'affiche. C'est une méthode très pratique pour éviter de redessiner un
nouveau bouton, dès que l'on change son texte. De cette façon, ils sont
générés dynamiquement.
</para>
</section>
<section xml:id="image.examples-watermark">
<title>Ajout d'un tatouage numérique sur des images en utilisant un canal Alpha</title>
<para>
<example>
<title>Ajout d'un tatouage numérique sur des images en utilisant un canal Alpha</title>
<programlisting role="php">
<![CDATA[
<?php
// Charge le cachet et la photo afin d'y appliquer le tatouage numérique
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');
// Définit les marges pour le cachet et récupère la hauteur et la largeur de celui-ci
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copie le cachet sur la photo en utilisant les marges et la largeur de la
// photo originale afin de calculer la position du cachet
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Affichage
header('Content-type: image/png');
imagepng($im);
?>
]]>
</programlisting>
<mediaobject>
<alt>Ajout d'un tatouage numérique à l'image en utilisant un canal alpha</alt>
<imageobject>
<imagedata fileref="en/reference/image/figures/watermarks.png" />
</imageobject>
</mediaobject>
</example>
Cet exemple montre un moyen simple d'appliquer un tatouage numérique
et un cachet aux photos et les images sous licence.
Il est à noter la présence d'un canal Alpha dans le cachet ainsi que du texte
anti-aliasé. Ces 2 éléments seront préservés lors de la copie.
</para>
</section>
<section xml:id="image.examples.merged-watermark">
<title>Exemple avec <function>imagecopymerge</function> pour créer un
tatouage numérique translucide</title>
<para>
<example>
<title>Exemple avec <function>imagecopymerge</function> pour créer un
tatouage numérique translucide</title>
<programlisting role="php">
<![CDATA[
<?php
// Charge le cachet et la photo afin d'y appliquer le tatouage numérique
$im = imagecreatefromjpeg('photo.jpeg');
// Tout d'abord, nous créons un cachet manuellement grâce à GD
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF);
imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF);
imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF);
imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF);
// Définit les marges du cachet et récupère la largeur et la hauteur du cachet
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Fusionne le cachet dans notre photo avec une opacité de 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Sauvegarde l'image dans un fichier
imagepng($im, 'photo_stamp.png');
?>
]]>
</programlisting>
<mediaobject>
<alt>Utilisation d'imagecopymerge() pour créer un tatouage translucide</alt>
<imageobject>
<imagedata fileref="en/reference/image/figures/watermark-merged.png" />
</imageobject>
</mediaobject>
</example>
Cet exemple utilise la fonction <function>imagecopymerge</function>
pour fusionner le cachet avec notre image originale. En utilisant cette
fonction, nous pouvons définir l'opacité de notre cachet - dans notre
exemple, nous l'avons défini à 50%. En pratique, il est plus judicieux
de rendre notre protection semi-transparente, la rendant plus difficile à
enlever mais permettant également aux visionneuses d'images de la lire sans
problème.
</para>
</section>
</chapter>
<!-- 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
-->