-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathexamples.xml
More file actions
150 lines (138 loc) · 5.14 KB
/
examples.xml
File metadata and controls
150 lines (138 loc) · 5.14 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
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: PhilDaiguille 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>Creación de una imagen PNG con PHP</title>
<para>
<example>
<title>Creación de una imagen PNG con 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>
Este ejemplo debe ser llamado desde una página HTML con una etiqueta
de imagen como: <literal><img src="button.php?text"></literal>.
El script anterior, <filename>button.php</filename>, toma el string
<literal>"texto"</literal> y lo escribe
sobre el fondo de imagen llamado <literal>"images/button1.png"</literal>,
luego lo muestra. Este es un método muy práctico para evitar redibujar
un nuevo botón cada vez que se cambia su texto. De esta manera, se generan
dinámicamente.
</para>
</section>
<section xml:id="image.examples-watermark">
<title>Añadir un sello digital a imágenes utilizando un canal Alpha</title>
<para>
<example>
<title>Añadir un sello digital a imágenes utilizando un canal Alpha</title>
<programlisting role="php">
<![CDATA[
<?php
// Carga el sello y la foto para aplicar el sello digital
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');
// Define los márgenes para el sello y obtiene la altura y anchura de este
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copia el sello sobre la foto utilizando los márgenes y la anchura de la
// foto original para calcular la posición del sello
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Mostrar
header('Content-type: image/png');
imagepng($im);
?>
]]>
</programlisting>
<mediaobject>
<alt>Añadir un sello digital a la imagen utilizando un canal alpha</alt>
<imageobject>
<imagedata fileref="en/reference/image/figures/watermarks.png" />
</imageobject>
</mediaobject>
</example>
Este ejemplo muestra un método simple para aplicar un sello digital
y un sello a sus fotos e imágenes con licencia.
Observe la presencia de un canal Alpha en el sello así como texto
anti-aliaseado. Estos dos elementos serán preservados durante la copia.
</para>
</section>
<section xml:id="image.examples.merged-watermark">
<title>Ejemplo con <function>imagecopymerge</function> para crear un
sello digital translúcido</title>
<para>
<example>
<title>Ejemplo con <function>imagecopymerge</function> para crear un
sello digital translúcido</title>
<programlisting role="php">
<![CDATA[
<?php
// Carga el sello y la foto para aplicar el sello digital
$im = imagecreatefromjpeg('photo.jpeg');
// Primero, creamos un sello manualmente usando 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);
// Define los márgenes del sello y obtiene la anchura y altura del sello
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Fusiona el sello en nuestra foto con una opacidad del 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Guarda la imagen en un archivo
imagepng($im, 'photo_stamp.png');
?>
]]>
</programlisting>
<mediaobject>
<alt>Uso de imagecopymerge() para crear un sello translúcido</alt>
<imageobject>
<imagedata fileref="en/reference/image/figures/watermark-merged.png" />
</imageobject>
</mediaobject>
</example>
Este ejemplo utiliza la función <function>imagecopymerge</function>
para fusionar el sello con nuestra imagen original. Usando esta
función, podemos definir la opacidad de nuestro sello - en nuestro
ejemplo, lo hemos establecido en 50%. En la práctica, es más conveniente
hacer nuestra protección semi-transparente, lo que la hace más difícil de
eliminar pero también permite a los visores de imágenes leerla sin problemas.
</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
-->