mirror of
https://github.com/php/doc-es.git
synced 2026-04-25 08:08:27 +02:00
09d66981d3
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@337177 c90b9560-bf6c-de11-be94-00142212c4b1
271 lines
8.2 KiB
XML
271 lines
8.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: addba5dcce72f6c9e66751d0d12fa830bdef4707 Maintainer: seros Status: ready -->
|
|
<refentry xml:id="function.imagecopyresampled" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>imagecopyresampled</refname>
|
|
<refpurpose>Copia y cambia el tamaño de parte de una imagen redimensionándola</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>imagecopyresampled</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>imagecopyresampled</function> copia una porción
|
|
rectangular de una imagen a otra imagen, interpolando de manera suave los valores
|
|
de los píxeles por lo que, particularmete, al reducir el tamaño de una imagen,
|
|
ésta todavía conserva mucha nitidez.
|
|
</para>
|
|
<para>
|
|
En otras palabras, <function>imagecopyresampled</function> tomará un
|
|
área rectangular de <parameter>src_image</parameter> de ancho
|
|
<parameter>src_w</parameter> y alto <parameter>src_h</parameter> en la
|
|
posición (<parameter>src_x</parameter>,<parameter>src_y</parameter>)
|
|
y la coloca en un área rectangular de <parameter>dst_image</parameter>
|
|
de ancho <parameter>dst_w</parameter> y alto <parameter>dst_h</parameter>
|
|
en la posición (<parameter>dst_x</parameter>,<parameter>dst_y</parameter>).
|
|
</para>
|
|
<para>
|
|
Si las coordenadas del origen y destino y los anchos y altos
|
|
difieren, se llevará a cabo la ampliación o reducción del fragmento
|
|
de la imagen. Las coodernadas se refiren a la esquina superior
|
|
izquierda. Esta función se puede usar para copiar regiones dentro de la
|
|
misma imagen (si <parameter>dst_image</parameter> es el mismo que
|
|
<parameter>src_image</parameter>) pero si las regiones se traslapan el
|
|
resultado será impredecible.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>dst_image</parameter></term>
|
|
<listitem>
|
|
<para>&gd.image.destination;</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>src_image</parameter></term>
|
|
<listitem>
|
|
<para>&gd.image.source;</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>dst_x</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Coordenada x del punto de destino.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>dst_y</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Coordenada y del punto de destino.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>src_x</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Coordenada x del punto de origen.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>src_y</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Coordenada y del punto de origen.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>dst_w</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Ancho del destino.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>dst_h</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Alto del destino.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>src_w</parameter></term>
|
|
<listitem>
|
|
<para>&gd.source.width;</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>src_h</parameter></term>
|
|
<listitem>
|
|
<para>&gd.source.height;</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo sencillo</title>
|
|
<para>
|
|
Este ejemplo redimensionará una imagen a la mitad de su tamaño original.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// El archivo
|
|
$nombre_archivo = 'prueba.jpg';
|
|
$porcentaje = 0.5;
|
|
|
|
// Tipo de contenido
|
|
header('Content-Type: image/jpeg');
|
|
|
|
// Obtener nuevas dimensiones
|
|
list($ancho, $alto) = getimagesize($nombre_archivo);
|
|
$nuevo_ancho = $ancho * $porcentaje;
|
|
$nuevo_alto = $alto * $porcentaje;
|
|
|
|
// Redimensionar
|
|
$imagen_p = imagecreatetruecolor($nuevo_ancho, $nuevo_alto);
|
|
$imagen = imagecreatefromjpeg($nombre_archivo);
|
|
imagecopyresampled($imagen_p, $imagen, 0, 0, 0, 0, $nuevo_ancho, $nuevo_alto, $ancho, $alto);
|
|
|
|
// Imprimir
|
|
imagejpeg($imagen_p, null, 100);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<mediaobject>
|
|
<alt>Salida del ejemplo : Ejemplo sencillo</alt>
|
|
<imageobject>
|
|
<imagedata fileref="en/reference/image/figures/imagecopyresampled.jpg"/>
|
|
</imageobject>
|
|
</mediaobject>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Redimensionar una imagen proporcionalmente</title>
|
|
<para>
|
|
Este ejemplo mostrará una imagen con el ancho,
|
|
o alto, máximo de 200 píxeles.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// El archivo
|
|
$nombre_archivo = 'prueba.jpg';
|
|
|
|
// Establecer un ancho y alto máximo
|
|
$ancho = 200;
|
|
$alto = 200;
|
|
|
|
// Tipo de contenido
|
|
header('Content-Type: image/jpeg');
|
|
|
|
// Obtener las nuevas dimensiones
|
|
list($ancho_orig, $alto_orig) = getimagesize($nombre_archivo);
|
|
|
|
$ratio_orig = $ancho_orig/$alto_orig;
|
|
|
|
if ($ancho/$alto > $ratio_orig) {
|
|
$ancho = $alto*$ratio_orig;
|
|
} else {
|
|
$alto = $ancho/$ratio_orig;
|
|
}
|
|
|
|
// Redimensionar
|
|
$image_p = imagecreatetruecolor($ancho, $alto);
|
|
$image = imagecreatefromjpeg($nombre_archivo);
|
|
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $ancho, $alto, $ancho_orig, $alto_orig);
|
|
|
|
// Imprimir
|
|
imagejpeg($image_p, null, 100);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<mediaobject>
|
|
<alt>Salida del ejemplo : Redimensionar una imagen proporcionalmente</alt>
|
|
<imageobject>
|
|
<imagedata fileref="en/reference/image/figures/imagecopyresampled_2.jpg"/>
|
|
</imageobject>
|
|
</mediaobject>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Hay un problema debido a las limitaciones de la imagen de paleta (255+1 colores).
|
|
Redimensionar o filtrar una imagen normalmente necesita más de 255 colores, se usa
|
|
un tipo de aproximación para calcular el nuevo píxel redimensionado y su color.
|
|
Con una imagen de paleta tratamos de asignar un color nuevo, si falló,
|
|
escogemos el color computado más próximo (en teoría). Éste no es
|
|
siempre el color visual más próximo. Puede producir un resultado extraño, como
|
|
imágenes en blaco (o visualmente en blaco). Para saltarse este problema, por favor use una
|
|
imagen de color verdadero como imagen de destino, como una creada por
|
|
<function>imagecreatetruecolor</function>.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<function>imagecopyresized</function>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- 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
|
|
-->
|