* Fixing minor errors / adding improvements on many gd related functions with help from Ross Masters

* Added watermark examples on the main page based on Pierre's code by Ross Masters
* Added examples for the following functions
 * imagefilter
 * imageftbbox
 * imagegif
 * imagepsbbox
 * imagettfbbox
 * iptcembed
* Following examples are by Ross Masters
 * imagealphablending
 * imagecolorexact
 * imagecolorexactalpha
 * imagecolormatch
 * imagecolorresolve
 * imagecolorresolvealpha
 * imagegd
 * imagegd2
 * imagelayereffect
 * imagepstext


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@265588 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kalle Sommer Nielsen 2008-08-28 19:03:16 +00:00
parent ac01e6d92f
commit 0ebb1e4ec0
41 changed files with 1129 additions and 262 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<chapter xml:id="image.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
@ -34,6 +34,92 @@ imagedestroy($im);
dynamically generated.
</para>
</section>
<section xml:id="image.examples-watermark">
<para>
<example>
<title>Adding watermarks to images using alpha channels</title>
<programlisting role="php">
<![CDATA[
<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.watermarks.png" />
</imageobject>
</mediaobject>
</example>
This example is a common way to add watermarks and stamps to photos and
copyrighted images. Note that the presence of an alpha channel in the
stamp image as the text is anti-aliased. This is preserved during copying.
</para>
</section>
<section xml:id="image.examples.merged-watermark">
<para>
<example>
<title>Using <function>imagecopymerge</function> to create a translucent watermark</title>
<programlisting role="php">
<![CDATA[
<?php
// Load the stamp and the photo to apply the watermark to
$im = imagecreatefromjpeg('photo.jpeg');
// First we create our stamp image manually from GD
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0,0, 99, 99, 0x0000FF);
imagefilledrectangle($stamp, 9,9, 90,60, 0xFFFFFF);
$im = imagecreatefromjpeg('photo.jpeg');
imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF);
imagestring($stamp, 3, 20, 40, '(c) 2007-8', 0x0000FF);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Merge the stamp onto our photo with an opacity (transparency) of 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Save the image to file and free memory
imagepng($im, 'photo_stamp.png');
imagedestroy($im);
?>
]]>
</programlisting>
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.watermark-merged.png" />
</imageobject>
</mediaobject>
</example>
This example uses <function>imagecopymerge</function> to merge the stamp
with our original image. Using this we can set the opacity of our stamp -
in our example we've set it to 50% opacity (another term for transparency).
In practice this would be useful in copyright protection as semi-transparent
watermarks are hard to remove yet allow viewers to see the image.
</para>
</section>
</chapter>
<!-- Keep this comment at the end of the file

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<refentry xml:id="function.imagealphablending" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagealphablending</refname>
@ -47,6 +47,32 @@
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>imagealphablending</function> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
// Create image
$im = imagecreatetruecolor(100, 100);
// Set alphablending to on
imagealphablending($im, true);
// Draw a square
imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));
// Output
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.gd.2;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<refentry xml:id="function.imagecolorat" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorat</refname>
@ -78,6 +78,30 @@ var_dump($r, $g, $b);
int(119)
int(123)
int(180)
]]>
</screen>
</example>
<example>
<title>Human-readable RGB values using <function>imagecolorsforindex</function></title>
<programlisting role="php">
<![CDATA[
<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
list($r, $g, $b, $alpha) = imagecolorsforindex($rgb);
var_dump($r, $g, $b, $alpha);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
int(119)
int(123)
int(180)
int(127)
]]>
</screen>
</example>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<refentry xml:id='function.imagecolorclosesthwb' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorclosesthwb</refname>
@ -111,7 +111,6 @@ HWB: 33
<para>
<simplelist>
<member><function>imagecolorclosest</function></member>
<member><function>imagecolorclosesthwb</function></member>
</simplelist>
</para>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<refentry xml:id="function.imagecolorexact" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorexact</refname>
@ -62,6 +62,41 @@
color does not exist.
</para>
</refsect1>
<refsect1 role="examples">
<example>
<title>Get colors from the GD logo</title>
<programlisting role="php">
<![CDATA[
<?php
// Setup an image
$im = imagecreatefrompng('./gdlogo.png');
$colors = Array();
$colors[] = imagecolorexact($im, 255, 0, 0);
$colors[] = imagecolorexact($im, 0, 0, 0);
$colors[] = imagecolorexact($im, 255, 255, 255);
$colors[] = imagecolorexact($im, 100, 255, 52);
print_r($colors);
// Free from memory
imagedestroy($im);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => 16711680
[1] => 0
[2] => 16777215
[3] => 6618932
)
]]>
</screen>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<refentry xml:id="function.imagecolorexactalpha" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorexactalpha</refname>
@ -71,6 +71,42 @@
image, or -1 if the color does not exist in the image's palette.
</para>
</refsect1>
<refsect1 role="examples">
<example>
<title>Get colors from the GD logo</title>
<programlisting role="php">
<![CDATA[
<?php
// Setup an image
$im = imagecreatefrompng('./gdlogo.png');
$colors = Array();
$colors[] = imagecolorexactalpha($im, 255, 0, 0, 0);
$colors[] = imagecolorexactalpha($im, 0, 0, 0, 127);
$colors[] = imagecolorexactalpha($im, 255, 255, 255, 55);
$colors[] = imagecolorexactalpha($im, 100, 255, 52, 20);
print_r($colors);
// Free from memory
imagedestroy($im);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => 16711680
[1] => 2130706432
[2] => 939524095
[3] => 342163252
)
]]>
</screen>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.gd.2;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- $Revision: 1.10 $ -->
<refentry xml:id="function.imagecolormatch" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolormatch</refname>
@ -46,6 +46,33 @@
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
<example>
<title><function>imagecolormatch</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// Setup the true color and palette images
$im1 = imagecreatefrompng('./gdlogo.png');
$im2 = imagecreate(imagesx($im1), imagesy($im1));
// Add some colors to $im2
$colors = Array();
$colors[] = imagecolorallocate($im2, 255, 36, 74);
$colors[] = imagecolorallocate($im2, 40, 0, 240);
$colors[] = imagecolorallocate($im2, 82, 100, 255);
$colors[] = imagecolorallocate($im2, 84, 63, 44);
// Match these colors with the true color image
imagecolormatch($im1, $im2);
// Free from memory
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.bundled.gd;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<refentry xml:id="function.imagecolorresolve" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorresolve</refname>
@ -62,6 +62,40 @@
Returns a color index.
</para>
</refsect1>
<refsect1 role="examples">
&refitle.examples;
<example>
<title>Using <function>imagecoloresolve</function> to get colors from an image</title>
<programlisting role="php">
<![CDATA[
<?php
// Load an image
$im = imagecreatefromgif('phplogo.gif');
// Get closest colors from the image
$colors = array();
$colors[] = imagecolorresolve($im, 255, 255, 255, 0);
$colors[] = imagecolorresolve($im, 0, 0, 200, 127);
// Output
print_r($colors);
imagedestroy($im);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => 89
[1] => 85
)
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<refentry xml:id="function.imagecolorresolvealpha" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorresolvealpha</refname>
@ -71,6 +71,40 @@
Returns a color index.
</para>
</refsect1>
<refsect1 role="examples">
&refitle.examples;
<example>
<title>Using <function>imagecoloresolve</function> to get colors from an image</title>
<programlisting role="php">
<![CDATA[
<?php
// Load an image
$im = imagecreatefromgif('phplogo.gif');
// Get closest colors from the image
$colors = array();
$colors[] = imagecolorresolve($im, 255, 255, 255, 0);
$colors[] = imagecolorresolve($im, 0, 0, 200, 127);
// Output
print_r($colors);
imagedestroy($im);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => 89
[1] => 85
)
]]>
</screen>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.gd.2;

View file

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<refentry xml:id="function.imagecolorset" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecolorset</refname>
<refpurpose>Set the color for the specified palette index</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
@ -23,7 +22,6 @@
flood-fill.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
@ -64,14 +62,12 @@
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
@ -103,7 +99,6 @@ imagedestroy($im);
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- $Revision: 1.13 $ -->
<refentry xml:id="function.imagecopyresized" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecopyresized</refname>
@ -176,7 +176,7 @@ imagejpeg($thumb);
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagecopyresized.png"/>
<imagedata fileref="figures/image.imagecopyresized.jpg"/>
</imageobject>
</mediaobject>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.20 $ -->
<!-- $Revision: 1.21 $ -->
<refentry xml:id="function.imagecreatefromgif" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecreatefromgif</refname>
@ -15,41 +15,6 @@
<function>imagecreatefromgif</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
To ease debugging the following example will produce an error GIF:
<example>
<title>Example to handle an error during creation</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadGif ($imgname)
{
$im = @imagecreatefromgif ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor (150, 30); /* Create a blank image */
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
header("Content-Type: image/gif");
$img = LoadGif("bogus.image");
imagegif($img);
imagedestroy($img);
?>
]]>
</programlisting>
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagecreatefromgif.gif"/>
</imageobject>
</mediaobject>
</example>
</para>
&tip.fopen-wrapper;
</refsect1>
<refsect1 role="parameters">
@ -73,6 +38,51 @@ imagedestroy($img);
Returns an image resource identifier on success, &false; on errors.
</para>
</refsect1>
<refsect1 role="examples">
<example>
<title>Example to handle an error during loading of a GIF</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadGif($imgname)
{
/* Attempt to open */
$im = @imagecreatefromgif($imgname);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor (150, 30);
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/gif');
$img = LoadGif('bogus.image');
imagegif($img);
imagedestroy($img);
?>
]]>
</programlisting>
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagecreatefromgif.gif"/>
</imageobject>
</mediaobject>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.20 $ -->
<!-- $Revision: 1.21 $ -->
<refentry xml:id="function.imagecreatefromjpeg" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecreatefromjpeg</refname>
@ -15,44 +15,6 @@
<function>imagecreatefromjpeg</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
On failure <function>imagecreatefromjpeg</function> outputs an error message,
which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error <acronym>JPEG</acronym>:
<example>
<title>Example to handle an error during creation</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a black image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
header("Content-Type: image/jpeg");
$img = LoadJpeg("bogus.image");
imagejpeg($img);
imagedestroy($img);
?>
]]>
</programlisting>
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagecreatefromjpeg.jpg"/>
</imageobject>
</mediaobject>
</example>
</para>
&tip.fopen-wrapper;
</refsect1>
<refsect1 role="parameters">
@ -76,6 +38,51 @@ imagedestroy($img);
Returns an image resource identifier on success, &false; on errors.
</para>
</refsect1>
<refsect1 role="examples">
<example>
<title>Example to handle an error during loading of a JPEG</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadJpeg($imgname)
{
/* Attempt to open */
$im = @imagecreatefromjpeg($imgname);
/* See if it failed */
if(!$im)
{
/* Create a black image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);
?>
]]>
</programlisting>
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagecreatefromjpeg.jpg"/>
</imageobject>
</mediaobject>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.config.jpeg;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.16 $ -->
<!-- $Revision: 1.17 $ -->
<refentry xml:id="function.imagecreatefrompng" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecreatefrompng</refname>
@ -15,44 +15,6 @@
<function>imagecreatefrompng</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
<function>imagecreatefrompng</function> returns an empty string
on failure. It also outputs an error message, which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error <acronym>PNG</acronym>:
<example>
<title>Example to handle an error during creation</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadPNG($imgname)
{
$im = @imagecreatefrompng($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
header("Content-Type: image/png");
$img = LoadPNG("bogus.image");
imagepng($img);
imagedestroy($img);
?>
]]>
</programlisting>
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagecreatefrompng.gif"/>
</imageobject>
</mediaobject>
</example>
</para>
&tip.fopen-wrapper;
</refsect1>
<refsect1 role="parameters">
@ -76,6 +38,46 @@ imagedestroy($img);
Returns an image resource identifier on success, &false; on errors.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Example to handle an error during loading of a PNG</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadPNG($imgname)
{
/* Attempt to open */
$im = @imagecreatefrompng($imgname);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/png');
$img = LoadPNG('bogus.image');
imagepng($img);
imagedestroy($img);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&warn.no-win32-fopen-wrapper;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<refentry xml:id="function.imagecreatefromwbmp" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecreatefromwbmp</refname>
@ -15,34 +15,6 @@
<function>imagecreatefromwbmp</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
<function>imagecreatefromwbmp</function> returns an empty string
on failure. It also outputs an error message, which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error <acronym>WBMP</acronym>:
<example>
<title>Example to handle an error during creation</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadWBMP($imgname)
{
$im = @imagecreatefromwbmp($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor (20, 20); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 10, 10, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
?>
]]>
</programlisting>
</example>
</para>
&tip.fopen-wrapper;
</refsect1>
<refsect1 role="parameters">
@ -66,6 +38,46 @@ function LoadWBMP($imgname)
Returns an image resource identifier on success, &false; on errors.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Example to handle an error during loading of a WBMP</title>
<programlisting role="php">
<![CDATA[
<?php
function LoadWBMP($imgname)
{
/* Attempt to open */
$im = @imagecreatefromwbmp($imgname);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor (20, 20);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 10, 10, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/png');
$img = LoadPNG('bogus.image');
imagwbmp($img);
imagedestroy($img);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.config.wbmp;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- $Revision: 1.10 $ -->
<refentry xml:id="function.imagecreatefromxbm" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagecreatefromxbm</refname>
@ -16,7 +16,6 @@
representing the image obtained from the given filename.
</para>
&tip.fopen-wrapper;
&warn.no-win32-fopen-wrapper;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
@ -59,6 +58,10 @@ imagedestroy($xbm);
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&warn.no-win32-fopen-wrapper;
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<refentry xml:id="function.imagefilter" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagefilter</refname>
@ -189,7 +189,6 @@
&return.success;
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
@ -213,7 +212,6 @@
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
@ -223,10 +221,15 @@
<![CDATA[
<?php
$im = imagecreatefrompng('dave.png');
if ($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
if($im && imagefilter($im, IMG_FILTER_GRAYSCALE))
{
echo 'Image converted to grayscale.';
imagepng($im, 'dave.png');
} else {
}
else
{
echo 'Conversion to grayscale failed.';
}
@ -241,14 +244,18 @@ imagedestroy($im);
<![CDATA[
<?php
$im = imagecreatefrompng('sean.png');
if ($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)) {
if($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20))
{
echo 'Image brightness changed.';
imagepng($im, 'sean.png');
} else {
imagedestroy($im);
}
else
{
echo 'Image brightness change failed.';
}
imagedestroy($im);
?>
]]>
</programlisting>
@ -261,14 +268,63 @@ imagedestroy($im);
$im = imagecreatefrompng('philip.png');
/* R, G, B, so 0, 255, 0 is green */
if ($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)) {
if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0))
{
echo 'Image successfully shaded green.';
imagepng($im, 'philip.png');
} else {
imagedestroy($im);
}
else
{
echo 'Green shading failed.';
}
?>
]]>
</programlisting>
</example>
<example>
<title><function>imagefilter</function> negate example</title>
<programlisting role="php">
<![CDATA[
<?php
// Define our negate function so its portable for
// php versions without imagefilter()
function negate($im)
{
if(function_exists('imagefilter'))
{
return imagefilter($im, IMG_FILTER_NEGATE);
}
imagedestroy($im);
for($x = 0; $x < imagesx($im); ++$x)
{
for($y = 0; $y < imagesy($im); ++$y)
{
$index = imagecolorat($im, $x, $y);
$rgb = imagecolorsforindex($index);
$color = imagecolorallocate($im, (255 - $rgb['red'], (255 - $rgb['green'], (255 - $rgb['blue']);
imagesetpixel($im, $x, $y, $color);
}
}
return(true);
}
$im = imagecreatefromjpeg('kalle.jpg');
if($im && negate($im))
{
echo 'Image successfully converted to negative colors.';
imagejpeg($im, 'kalle.jpg', 100);
imagedestroy($im);
}
else
{
echo 'Converting to negative colors failed.';
}
?>
]]>
</programlisting>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<refentry xml:id='function.imageftbbox' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imageftbbox</refname>
@ -24,7 +24,8 @@
<term><parameter>size</parameter></term>
<listitem>
<para>
The font size in pixels.
The font size. Depending on your version of GD, this should be
specified as the pixel size (GD1) or point size (GD2).
</para>
</listitem>
</varlistentry>
@ -136,6 +137,45 @@
corner seeing the text horizontally.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>imageftbbox</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a 300x150 image
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Set the background to be white
imagefilledrectangle($im, 0, 0, 299, 299, $white);
// Path to our font file
$font = './arial.ttf';
// First we create our bounding box
$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group');
// This is our cordinates for X and Y
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.gd.2;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.17 $ -->
<!-- $Revision: 1.18 $ -->
<refentry xml:id='function.imagefttext' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagefttext</refname>
@ -28,7 +28,8 @@
<varlistentry>
<term><parameter>size</parameter></term>
<listitem>
<para>The font size to use in points.
<para>
The font size to use in points.
</para>
</listitem>
</varlistentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<refentry xml:id='function.imagegd' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagegd</refname>
@ -39,6 +39,52 @@
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Outputting a GD image</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
// Output the image
imagegd($im);
// Free up memory
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Saving a GD image</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
// Save the gd image
// The file format for GD limages is .gd, see http://www.libgd.org/GdFileFormats
imagegd($im, 'simple.gd');
// Free up memory
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<refentry xml:id='function.imagegd2' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagegd2</refname>
@ -59,6 +59,51 @@
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Outputting a GD2 image</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagegd2($im);
// Free up memory
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Saving a GD2 image</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
// Save the gd2 image
// The file format for GD2 limages is .gd2, see http://www.libgd.org/GdFileFormats
imagegd2($im, 'simple.gd');
// Free up memory
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.gd.2;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<refentry xml:id="function.imagegif" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>imagegif</refname>
@ -49,6 +49,55 @@
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Outputting an image using <function>imagegif</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Create a new image instance
$im = imagecreatetruecolor(100, 100);
// Make the background white
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);
// Draw a text string on the image
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);
// Output the image to browser
header('Content-type: image/gif');
imagegif($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
<example>
<title>Converting a PNG image to GIF using <function>imagegif</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Load the PNG
$png = imagecreatefrompng('./php.png');
// Save the image as a GIF
imagegif($png, './php.gif');
// Free from memory
imagedestroy($png);
// We're done
echo 'Converted PNG image to GIF with success!';
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
@ -71,20 +120,52 @@
<programlisting role="php">
<![CDATA[
<?php
if (function_exists("imagegif")) {
header("Content-type: image/gif");
// Create a new image instance
$im = imagecreatetruecolor(100, 100);
// Do some image operations here
// Handle output
if(function_exists('imagegif'))
{
// For GIF
header('Content-type: image/gif');
imagegif($im);
} elseif (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
imagejpeg($im, "", 0.5);
} elseif (function_exists("imagepng")) {
header("Content-type: image/png");
}
elseif(function_exists('imagejpeg'))
{
// For JPEG
header('Content-type: image/jpeg');
imagejpeg($im, NULL, 100);
}
elseif(function_exists('imagepng'))
{
// For PNG
header('Content-type: image/png');
imagepng($im);
} elseif (function_exists("imagewbmp")) {
header("Content-type: image/vnd.wap.wbmp");
}
elseif(function_exists('imagewbmp'))
{
// For WBMP
header('Content-type: image/vnd.wap.wbmp');
imagewbmp($im);
} else {
die("No image support in this PHP server");
}
else
{
imagedestroy($im);
die('No image support in this PHP server');
}
// If image support was found for one of these
// formats, then free it from memory
if($im)
{
imagedestroy($im);
}
?>
]]>
@ -94,7 +175,7 @@ if (function_exists("imagegif")) {
</note>
<note>
<para>
As of version 3.0.18 and 4.0.2 you can use the function
As of PHP 3.0.18 and 4.0.2 you can use the function
<function>imagetypes</function> in place of
<function>function_exists</function> for checking
the presence of the various supported image formats:
@ -102,10 +183,13 @@ if (function_exists("imagegif")) {
<programlisting role="php">
<![CDATA[
<?php
if (imagetypes() & IMG_GIF) {
header ("Content-type: image/gif");
imagegif ($im);
} elseif (imagetypes() & IMG_JPG) {
if(imagetypes() & IMG_GIF)
{
header('Content-type: image/gif');
imagegif($im);
}
elseif(imagetypes() & IMG_JPG)
{
/* ... etc. */
}
?>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.8 $ -->
<!-- $Revision: 1.9 $ -->
<refentry xml:id="function.imagelayereffect" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagelayereffect</refname>
@ -76,6 +76,42 @@
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
<example>
<title><function>imagelayereffect</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// Setup an image
$im = imagecreatetruecolor(100, 100);
// Set a background
imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 220, 220, 220));
// Apply the overlay alpha blending flag
imagelayereffect($im, IMG_EFFECT_OVERLAY);
// Draw two grey ellipses
imagefilledellipse($im, 50, 50, 40, 40, imagecolorallocate($im, 100, 255, 100));
imagefilledellipse($im, 50, 50, 50, 80, imagecolorallocate($im, 100, 100, 255));
imagefilledellipse($im, 50, 50, 80, 50, imagecolorallocate($im, 255, 100, 100));
// Output
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
&example.outputs.similar;
<mediaobject>
<imageobject>
<imagedata fileref="figures/image.imagelayereffect.png"/>
</imageobject>
</mediaobject>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.bundled.gd;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- $Revision: 1.13 $ -->
<refentry xml:id="function.imageline" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imageline</refname>
@ -17,7 +17,7 @@
<methodparam><type>int</type><parameter>color</parameter></methodparam>
</methodsynopsis>
<para>
<function>imageline</function> draws a line between the two given points.
Draws a line between the two given points.
</para>
</refsect1>
<refsect1 role="parameters">

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<!-- $Revision: 1.10 $ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.imageloadfont">
<refnamediv>
<refname>imageloadfont</refname>
@ -90,18 +90,27 @@
&reftitle.examples;
<para>
<example>
<title>Using imageloadfont</title>
<title><function>imageloadfont</function> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
header("Content-type: image/png");
// Create a new image instance
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background white
imagefilledrectangle($im, 0, 0, 49, 19, $white);
$font = imageloadfont("04b.gdf");
imagestring($im, $font, 0, 0, "Hello", $black);
// Load the gd font and write 'Hello'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Hello', $black);
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.14 $ -->
<!-- $Revision: 1.15 $ -->
<refentry xml:id="function.imagepng" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagepng</refname>
@ -107,7 +107,11 @@
<![CDATA[
<?php
$im = imagecreatefrompng("test.png");
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<refentry xml:id="function.imagepolygon" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagepolygon</refname>
@ -28,8 +28,29 @@
<term><parameter>points</parameter></term>
<listitem>
<para>
An array containing the polygon's vertices, i.e. points[0] = x0,
points[1] = y0, points[2] = x1, points[3] = y1, etc.
An array containing the polygon's vertices, e.g.:
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>points[0]</entry>
<entry>= x0</entry>
</row>
<row>
<entry>points[1]</entry>
<entry>= y0</entry>
</row>
<row>
<entry>points[2]</entry>
<entry>= x1</entry>
</row>
<row>
<entry>points[3]</entry>
<entry>= y1</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</listitem>
</varlistentry>
@ -67,17 +88,17 @@
<programlisting role="php">
<![CDATA[
<?php
// create a blank image
// Create a blank image
$image = imagecreatetruecolor(400, 300);
// fill the background color
// Fill the background color
$bg = imagecolorallocate($image, 0, 0, 0);
// choose a color for the polygon
// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);
// draw the polygon
imagepolygon($image, array (
// Draw the polygon
imagepolygon($image, array(
0, 0,
100, 200,
300, 200
@ -85,10 +106,11 @@ imagepolygon($image, array (
3,
$col_poly);
// output the picture
header("Content-type: image/png");
imagepng($image);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
]]>
</programlisting>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.14 $ -->
<!-- $Revision: 1.15 $ -->
<refentry xml:id="function.imagepsbbox" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagepsbbox</refname>
@ -99,29 +99,66 @@
<para>
Returns an array containing the following elements:
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>left x-coordinate</entry>
</row>
<row>
<entry>1</entry>
<entry>upper y-coordinate</entry>
</row>
<row>
<entry>2</entry>
<entry>right x-coordinate</entry>
</row>
<row>
<entry>3</entry>
<entry>lower y-coordinate</entry>
</row>
</tbody>
</tgroup>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>left x-coordinate</entry>
</row>
<row>
<entry>1</entry>
<entry>upper y-coordinate</entry>
</row>
<row>
<entry>2</entry>
<entry>right x-coordinate</entry>
</row>
<row>
<entry>3</entry>
<entry>lower y-coordinate</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>imagepsbbox</function> usage</title>
<programlisting role="php">
<![CDATA[
<?php
// Create image handle
$im = imagecreatetruecolor(200, 200);
// Allocate colors
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Load the PostScript Font
$font = imagepsloadfont('font.pfm');
// Make a bounding box for the font
$bbox = imagepsbbox('Sample text is simple', $font, 12);
// Define our X and Y cordinates
$x = ($bbox[2] / 2) - 10;
$y = ($bbox[3] / 2) - 10;
// Write the font to the image
imagepstext($im, 'Sample text is simple', $font, 12, $black, $white, $x, $y);
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.config.t1lib;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.14 $ -->
<!-- $Revision: 1.15 $ -->
<refentry xml:id="function.imagepsloadfont" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagepsloadfont</refname>
@ -46,14 +46,22 @@
<programlisting role="php">
<![CDATA[
<?php
header("Content-type: image/png");
// Create a new image instance
$im = imagecreatetruecolor(350, 45);
// Allocate colors and fill the background
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 349, 44, $white);
$font = imagepsloadfont("bchbi.pfb"); // or locate your .pfb files on your machine
// Load a font, write to the image and free the font from memory
$font = imagepsloadfont("bchbi.pfb");
imagepstext($im, "Testing... It worked!", $font, 32, $white, $black, 32, 32);
imagepsfreefont($font);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<refentry xml:id="function.imagepstext" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagepstext</refname>
@ -168,6 +168,36 @@
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>imagepstext</function> usage</title>
<programlisting role="php">
<![CDATA[
<?php
// Create image handle
$im = imagecreatetruecolor(200, 200);
// Allocate colors
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Load the PostScript Font
$font = imagepsloadfont('font.pfm');
// Write the font to the image
imagepstext($im, 'Sample text is simple', $font, 12, $black, $white, 50, 50);
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.config.t1lib;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<refentry xml:id="function.imagesetbrush" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagesetbrush</refname>
@ -46,7 +46,7 @@
&reftitle.examples;
<para>
<example>
<title>Saving an XBM file</title>
<title><function>imagesetbrush</function> example</title>
<programlisting role="php">
<![CDATA[
<?php

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<refentry xml:id="function.imagesetthickness" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagesetthickness</refname>
@ -44,7 +44,7 @@
&reftitle.examples;
<para>
<example>
<title>Saving an XBM file</title>
<title><function>imagesetthickness</function> example</title>
<programlisting role="php">
<![CDATA[
<?php

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- $Revision: 1.13 $ -->
<refentry xml:id="function.imagesettile" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagesettile</refname>
@ -58,7 +58,7 @@
&reftitle.examples;
<para>
<example>
<title>Saving an XBM file</title>
<title><function>imagesettile</function> example</title>
<programlisting role="php">
<![CDATA[
<?php

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.17 $ -->
<!-- $Revision: 1.18 $ -->
<refentry xml:id="function.imagestring" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagestring</refname>
@ -76,19 +76,21 @@
<programlisting role="php">
<![CDATA[
<?php
// create a 100*30 image
// Create a 100*30 image
$im = imagecreate(100, 30);
// white background and blue text
// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left
imagestring($im, 5, 0, 0, "Hello world!", $textcolor);
// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);
// Output the image
header('Content-type: image/png');
// output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- $Revision: 1.13 $ -->
<refentry xml:id="function.imagettfbbox" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>imagettfbbox</refname>
@ -113,7 +113,57 @@
corner seeing the text horizontally.
</para>
</refsect1>
<refsect1 role="seealso">
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>imagettfbbox</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a 300x150 image
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Set the background to be white
imagefilledrectangle($im, 0, 0, 299, 299, $white);
// Path to our font file
$font = './arial.ttf';
// First we create our bounding box for the first text
$bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion());
// This is our cordinates for X and Y
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
// Write it
imagettftext($im, 10, 45, $x, $y, $black, $font, 'Powered by PHP ' . phpversion());
// Create the next bounding box for the second text
$bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version());
// Set the cordinates so its next to the first text
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
// Write it
imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_version());
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.seealso;
<note>
<para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 1.26 $ -->
<!-- $Revision: 1.27 $ -->
<refentry xml:id="function.imagettftext" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>imagettftext</refname>
@ -166,7 +166,7 @@ $font = 'SomeFont';
<![CDATA[
<?php
// Set the content-type
header("Content-type: image/png");
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- $Revision: 1.12 $ -->
<refentry xml:id="function.imagewbmp" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imagewbmp</refname>
@ -83,6 +83,7 @@ imagedestroy($im);
<title>Saving the WBMP image</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
@ -93,6 +94,7 @@ imagewbmp($im, 'simpletext.wbmp');
// Free up memory
imagedestroy($im);
?>
]]>
</programlisting>
</example>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<!-- $Revision: 1.8 $ -->
<refentry xml:id='function.iptcembed' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>iptcembed</refname>
@ -53,6 +53,71 @@
returned as a string, &false; on errors.
</para>
</refsect1>
<refsect role="examples">
&reftitle.examples;
<example>
<title>Embedding IPTC data into a JPEG</title>
<programlisting role="php">
<![CDATA[
<?php
// iptc_make_tag() function by Thies C. Arntzen
function iptc_make_tag($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
if($length < 0x8000)
{
$retval .= chr($length >> 8) . chr($length & 0xFF);
}
else
{
$retval .= chr(0x80) .
chr(0x04) .
chr(($length >> 24) & 0xFF) .
chr(($length >> 16) & 0xFF) .
chr(($length >> 8) & 0xFF) .
chr($length & 0xFF);
}
return $retval . $value;
}
// Path to jpeg file
$path = './phplogo.jpg';
// We need to check if theres any IPTC data in the jpeg image. If there is then
// bail out because we cannot embed any image that already has some IPTC data!
$image = getimagesize($path, $info);
if(isset($info['APP13']))
{
die('Error: IPTC data found in source image, cannot continue');
}
// Set the IPTC tags
$iptc = array(
'2#120' => 'Test image',
'2#116' => 'Copyright 2008, The PHP Group'
);
// Convert the IPTC tags into binary code
$data = '';
foreach($iptc as $tag => $string)
{
$tag = substr($tag, 2);
$data .= iptc_make_tag(2, substr($tag, 2), $string);
}
// Embed the IPTC data
$content = iptcembed($data, $path);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>