Added examples

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@169877 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Aidan Lister 2004-10-04 09:50:18 +00:00
parent 31248619d1
commit 6694acda51
2 changed files with 174 additions and 40 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/image.xml, last change in rev 1.36 -->
<refentry id="function.imagecopyresampled">
<refnamediv>
@ -10,30 +10,33 @@
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>imagecopyresampled</methodname>
<methodparam><type>resource</type><parameter>dst_im</parameter></methodparam>
<methodparam><type>resource</type><parameter>src_im</parameter></methodparam>
<methodparam><type>int</type><parameter>dstX</parameter></methodparam>
<methodparam><type>int</type><parameter>dstY</parameter></methodparam>
<methodparam><type>int</type><parameter>srcX</parameter></methodparam>
<methodparam><type>int</type><parameter>srcY</parameter></methodparam>
<methodparam><type>int</type><parameter>dstW</parameter></methodparam>
<methodparam><type>int</type><parameter>dstH</parameter></methodparam>
<methodparam><type>int</type><parameter>srcW</parameter></methodparam>
<methodparam><type>int</type><parameter>srcH</parameter></methodparam>
<methodparam><type>resource</type><parameter>dst_image</parameter></methodparam>
<methodparam><type>resource</type><parameter>src_image</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_x</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_y</parameter></methodparam>
<methodparam><type>int</type><parameter>src_x</parameter></methodparam>
<methodparam><type>int</type><parameter>src_y</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_w</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_h</parameter></methodparam>
<methodparam><type>int</type><parameter>src_w</parameter></methodparam>
<methodparam><type>int</type><parameter>src_h</parameter></methodparam>
</methodsynopsis>
<para>
<function>imagecopyresampled</function> copies a rectangular
portion of one image to another image, smoothly interpolating pixel
values so that, in particular, reducing the size of an image still
retains a great deal of clarity. &return.success;
<parameter>dst_im</parameter> is the destination image,
<parameter>src_im</parameter> is the source image identifier. If
retains a great deal of clarity.
&return.success;
</para>
<para>
<parameter>dst_image</parameter> is the destination image,
<parameter>src_image</parameter> is the source image identifier. If
the source and destination coordinates and width and heights
differ, appropriate stretching or shrinking of the image fragment
will be performed. The coordinates refer to the upper left
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if <parameter>dst_im</parameter> is the same as
<parameter>src_im</parameter>) but if the regions overlap the
same image (if <parameter>dst_image</parameter> is the same as
<parameter>src_image</parameter>) but if the regions overlap the
results will be unpredictable.
</para>
<note>
@ -50,8 +53,92 @@
</para>
</note>
&note.gd.2;
</refsect1>
<refsect1>
&reftitle.examples;
<para>
See also <function>imagecopyresized</function>.
<example>
<title>Simple example</title>
<para>
This example will resample an image to half its original size.
</para>
<programlisting role="php">
<![CDATA[
<?php
// The file
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Resampling an image proportionally</title>
<para>
This example will display an image with the maximum width,
or height, of 200 pixels.
</para>
<programlisting role="php">
<![CDATA[
<?php
// The file
$filename = 'test.jpg';
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>imagecopyresized</function>
</para>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- $Revision: 1.4 $ -->
<!-- splitted from ./en/functions/image.xml, last change in rev 1.36 -->
<refentry id="function.imagecopyresized">
<refnamediv>
@ -8,30 +8,30 @@
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>imagecopyresized</methodname>
<methodparam><type>resource</type><parameter>dst_im</parameter></methodparam>
<methodparam><type>resource</type><parameter>src_im</parameter></methodparam>
<methodparam><type>int</type><parameter>dstX</parameter></methodparam>
<methodparam><type>int</type><parameter>dstY</parameter></methodparam>
<methodparam><type>int</type><parameter>srcX</parameter></methodparam>
<methodparam><type>int</type><parameter>srcY</parameter></methodparam>
<methodparam><type>int</type><parameter>dstW</parameter></methodparam>
<methodparam><type>int</type><parameter>dstH</parameter></methodparam>
<methodparam><type>int</type><parameter>srcW</parameter></methodparam>
<methodparam><type>int</type><parameter>srcH</parameter></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>int</type><methodname>imagecopyresized</methodname>
<methodparam><type>resource</type><parameter>dst_image</parameter></methodparam>
<methodparam><type>resource</type><parameter>src_image</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_x</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_y</parameter></methodparam>
<methodparam><type>int</type><parameter>src_x</parameter></methodparam>
<methodparam><type>int</type><parameter>src_y</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_w</parameter></methodparam>
<methodparam><type>int</type><parameter>dst_h</parameter></methodparam>
<methodparam><type>int</type><parameter>src_w</parameter></methodparam>
<methodparam><type>int</type><parameter>src_h</parameter></methodparam>
</methodsynopsis>
<para>
<function>imagecopyresized</function> copies a rectangular
portion of one image to another image.
<parameter>Dst_im</parameter> is the destination image,
<parameter>src_im</parameter> is the source image identifier. If
the source and destination coordinates and width and heights
<parameter>dst_image</parameter> is the destination image,
<parameter>src_image</parameter> is the source image identifier.
If the source and destination coordinates and width and heights
differ, appropriate stretching or shrinking of the image fragment
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if <parameter>dst_im</parameter> is the same as
<parameter>src_im</parameter>) but if the regions overlap the
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if <parameter>dst_image</parameter> is the same as
<parameter>src_image</parameter>) but if the regions overlap the
results will be unpredictable.
</para>
<note>
@ -47,8 +47,55 @@
<function>imagecreatetruecolor</function>.
</para>
</note>
</refsect1>
<refsect1>
&reftitle.examples;
<para>
See also <function>imagecopyresampled</function>.
<example>
<title>Resizing an image</title>
<para>
This example will display the image at half size.
</para>
<programlisting role="php">
<![CDATA[
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreate($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>
]]>
</programlisting>
<para>
The image will be output at half size, though better
quality could be obtained using <function>imagecopyresampled</function>.
</para>
</example>
</para>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>imagecopyresampled</function>
</para>
</refsect1>
</refentry>