reference/image/functions/imagesavealpha.xml
c4986eebebbf5d715a3dfcc5a7f65035aab9ff8c
...
...
@@ -3,67 +3,97 @@
3
3
<refentry xml:id="function.imagesavealpha" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>imagesavealpha</refname>
6
-
<refpurpose>Set the flag to save full alpha channel information (as opposed to single-color transparency) when saving PNG images</refpurpose>
6
+
<refpurpose>Whether to retain full alpha channel information when saving images</refpurpose>
7
7
</refnamediv>
8
+

8
9
<refsect1 role="description">
9
10
&reftitle.description;
10
11
<methodsynopsis>
11
12
<type>bool</type><methodname>imagesavealpha</methodname>
12
-
<methodparam><type>resource</type><parameter>image</parameter></methodparam>
13
-
<methodparam><type>bool</type><parameter>saveflag</parameter></methodparam>
13
+
<methodparam><type>GdImage</type><parameter>image</parameter></methodparam>
14
+
<methodparam><type>bool</type><parameter>enable</parameter></methodparam>
14
15
</methodsynopsis>
15
16
<para>
16
-
<function>imagesavealpha</function> sets the flag to attempt to save
17
+
<function>imagesavealpha</function> sets the flag which determines whether to retain
17
18
full alpha channel information (as opposed to single-color transparency)
18
-
when saving PNG images.
19
-
</para>
20
-
<para>
21
-
You have to unset alphablending
22
-
(<literal>imagealphablending($im, false)</literal>), to use it.
19
+
when saving images.
20
+
This is only supported for image formats which support full alpha channel information,
21
+
i.e. <literal>PNG</literal>, <literal>WebP</literal> and <literal>AVIF</literal>.
22
+
<note>
23
+
<simpara>
24
+
<function>imagesavealpha</function> is only meaningful for <literal>PNG</literal>
25
+
images, since the full alpha channel is always saved for <literal>WebP</literal>
26
+
and <literal>AVIF</literal>. It is not recommended to rely on this behavior,
27
+
as it may change in the future. Thus, <function>imagesavealpha</function>
28
+
should be called deliberately also for <literal>WebP</literal> and
29
+
<literal>AVIF</literal> images.
30
+
</simpara>
31
+
</note>
23
32
</para>
24
33
<para>
25
-
Alpha channel is not supported by all browsers, if you have problem with
26
-
your browser, try to load your script with an alpha channel compliant
27
-
browser, e.g. latest Mozilla.
34
+
Alphablending has to be disabled (<code>imagealphablending($im, false)</code>)
35
+
to retain the alpha-channel in the first place.
28
36
</para>
29
37
</refsect1>
38
+

30
39
<refsect1 role="parameters">
31
40
&reftitle.parameters;
32
41
<para>
33
42
<variablelist>
34
43
&gd.image.description;
35
44
<varlistentry>
36
-
<term><parameter>saveflag</parameter></term>
45
+
<term><parameter>enable</parameter></term>
37
46
<listitem>
38
47
<para>
39
-
Whether to save the alpha channel or not. Default to &false;.
48
+
Whether to save the alpha channel or not. Defaults to &false;.
40
49
</para>
41
50
</listitem>
42
51
</varlistentry>
43
52
</variablelist>
44
53
</para>
45
54
</refsect1>
55
+

46
56
<refsect1 role="returnvalues">
47
57
&reftitle.returnvalues;
48
58
<para>
49
59
&return.success;
50
60
</para>
51
61
</refsect1>
62
+

63
+
<refsect1 role="changelog">
64
+
&reftitle.changelog;
65
+
<informaltable>
66
+
<tgroup cols="2">
67
+
<thead>
68
+
<row>
69
+
<entry>&Version;</entry>
70
+
<entry>&Description;</entry>
71
+
</row>
72
+
</thead>
73
+
<tbody>
74
+
&gd.changelog.image-param;
75
+
</tbody>
76
+
</tgroup>
77
+
</informaltable>
78
+
</refsect1>
79
+

52
80
<refsect1 role="examples">
53
81
&reftitle.examples;
54
82
<para>
55
83
<example>
56
-
<title><function>imagesavealpha</function> example</title>
84
+
<title>Basic <function>imagesavealpha</function> Usage</title>
57
85
<programlisting role="php">
58
86
<![CDATA[
59
87
<?php
60
-
// Load a png image with alpha channels
88
+
// Load a png image with alpha channel
61
89
$png = imagecreatefrompng('./alphachannel_example.png');
62
90

63
-
// Do required operations
64
-

65
-
// Turn off alpha blending and set alpha flag
91
+
// Turn off alpha blending
66
92
imagealphablending($png, false);
93
+

94
+
// Do desired operations
95
+

96
+
// Set alpha flag
67
97
imagesavealpha($png, true);
68
98

69
99
// Output image to browser
...
...
@@ -77,20 +107,14 @@ imagedestroy($png);
77
107
</example>
78
108
</para>
79
109
</refsect1>
80
-
<refsect1 role="notes">
81
-
&reftitle.notes;
82
-
&note.gd.2;
83
-
</refsect1>
110
+

84
111
<refsect1 role="seealso">
85
112
&reftitle.seealso;
86
-
<para>
87
-
<simplelist>
88
-
<member><function>imagealphablending</function></member>
89
-
</simplelist>
90
-
</para>
113
+
<simplelist>
114
+
<member><function>imagealphablending</function></member>
115
+
</simplelist>
91
116
</refsect1>
92
117
</refentry>
93
-

94
118
<!-- Keep this comment at the end of the file
95
119
Local variables:
96
120
mode: sgml
...
...
@@ -111,4 +135,3 @@ vim600: syn=xml fen fdm=syntax fdl=2 si
111
135
vim: et tw=78 syn=sgml
112
136
vi: ts=1 sw=1
113
137
-->
114
-

115
138