-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathexamples.xml
More file actions
149 lines (136 loc) · 5.54 KB
/
examples.xml
File metadata and controls
149 lines (136 loc) · 5.54 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
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: takagi Status: ready -->
<!-- CREDITS: hirokawa -->
<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>PHP による PNG の生成</title>
<para>
<example>
<title>PHP による PNG の生成</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>
この例のスクリプトは、<literal><img src="button.php?text"></literal>
のようなタグが書かれたページからコールされるものです。
上の <filename>button.php</filename> スクリプトは、この <literal>"text"</literal>
文字列を引数とし、
基本画像 <literal>"images/button1.png"</literal>
の上にこの文字列を重ねて描いた後、その画像を出力します。
この方法を使うと、ボタンのテキストが変わるたびに新たなボタンを作り直す羽目になることを回避できます。
この方法により、動的に画像ボタンを生成できるのです。
</para>
</section>
<section xml:id="image.examples-watermark">
<title>アルファチャネルを使用した、画像へのすかしの追加</title>
<para>
<example>
<title>アルファチャネルを使用した、画像へのすかしの追加</title>
<programlisting role="php">
<![CDATA[
<?php
// スタンプと、それをすかしとして適用する写真を読み込みます
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');
// スタンプの余白を設定し、スタンプ画像の幅と高さを取得します
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// スタンプ画像を写真の上にコピーします。余白の値と
// 写真の幅を元にスタンプの位置を決定します
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// 出力します
header('Content-type: image/png');
imagepng($im);
?>
]]>
</programlisting>
<mediaobject>
<alt>アルファチャネルを使用した、画像へのすかしの追加</alt>
<imageobject>
<imagedata fileref="en/reference/image/figures/watermarks.png" />
</imageobject>
</mediaobject>
</example>
この例は、すかしやスタンプを写真あるいは著作権つき画像に追加するための一般的な方法です。
スタンプ画像内のアルファチャネルのテキストはアンチエイリアス処理されることに注意しましょう。
画像をコピーしてもこれは残り続けます。
</para>
</section>
<section xml:id="image.examples.merged-watermark">
<title><function>imagecopymerge</function> による半透明なすかしの作成</title>
<para>
<example>
<title><function>imagecopymerge</function> による半透明なすかしの作成</title>
<programlisting role="php">
<![CDATA[
<?php
// スタンプと、それをすかしとして適用する写真を読み込みます
$im = imagecreatefromjpeg('photo.jpeg');
// まず、スタンプ画像を 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);
// スタンプの余白を設定し、スタンプ画像の幅と高さを取得します
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// スタンプを、50% の不透明度で写真に重ねます
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// 画像をファイルに保存します
imagepng($im, 'photo_stamp.png');
?>
]]>
</programlisting>
<mediaobject>
<alt>imagecopymerge() による半透明なすかしの作成</alt>
<imageobject>
<imagedata fileref="en/reference/image/figures/watermark-merged.png" />
</imageobject>
</mediaobject>
</example>
この例は、<function>imagecopymerge</function>
を使ってスタンプを元画像にかぶせます。
これを使うと、スタンプの不透明度を設定することができます。
今回の例では 50% の不透明度に設定しています。
この半透明のすかしを用いる方法は、著作権つきの画像を保護するのに便利です。
すかしをとるのは非常に難しく、またもとの画像の見栄えも損ねません。
</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
-->