<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.image.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.imagecolorallocatealpha.php',
    1 => 'imagecolorallocatealpha',
    2 => 'Asigna un color a una imagen',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'Funciones de GD e Im&aacute;genes',
  ),
  'prev' => 
  array (
    0 => 'function.imagecolorallocate.php',
    1 => 'imagecolorallocate',
  ),
  'next' => 
  array (
    0 => 'function.imagecolorat.php',
    1 => 'imagecolorat',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/image/functions/imagecolorallocatealpha.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imagecolorallocatealpha" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecolorallocatealpha</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.2, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imagecolorallocatealpha</span> &mdash; <span class="dc-title">Asigna un color a una imagen</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecolorallocatealpha-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagecolorallocatealpha</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.gdimage.php" class="type GdImage">GdImage</a></span> <code class="parameter">$image</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$red</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$green</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$blue</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$alpha</code></span><br>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imagecolorallocatealpha()</strong></span> se comporta como
   <span class="function"><a href="function.imagecolorallocate.php" class="function">imagecolorallocate()</a></span> con el parámetro adicional de
   transparencia <code class="parameter">alpha</code>.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecolorallocatealpha-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
<dt><code class="parameter">image</code></dt><dd><p class="para">
 Un objeto <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span>, retornado por una de las funciones de
 creación de imágenes, como <span class="function"><a href="function.imagecreatetruecolor.php" class="function">imagecreatetruecolor()</a></span>.
</p></dd>
    
     <dt><code class="parameter">red</code></dt>
     <dd>
      <p class="para">Valor del componente rojo.</p>
     </dd>
    
    
     <dt><code class="parameter">green</code></dt>
     <dd>
      <p class="para">Valor del componente verde.</p>
     </dd>
    
    
     <dt><code class="parameter">blue</code></dt>
     <dd>
      <p class="para">Valor del componente azul.</p>
     </dd>
    
    
     <dt><code class="parameter">alpha</code></dt>
     <dd>
      <p class="para">
       Un valor entre <code class="literal">0</code> y <code class="literal">127</code>.
       <code class="literal">0</code> indica opacidad completa mientras que
       <code class="literal">127</code> indica transparencia completa.
      </p>
     </dd>
    
   </dl>
   Los parámetros <code class="parameter">red</code>, <code class="parameter">green</code>
   y <code class="parameter">blue</code> son enteros comprendidos entre 0 y 255, o
   hexadecimales comprendidos entre 0x00 y 0xFF.
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecolorallocatealpha-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Un identificador de color o <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si la asignación falla.
  </p>
  <div class="warning"><strong class="warning">Advertencia</strong><p class="simpara">
 Esta función puede retornar <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, pero también puede retornar un valor equivalente a <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
 Por favor, lea la sección sobre los <a href="language.types.boolean.php" class="link">booleanos</a> para más información.
 Utilice el <a href="language.operators.comparison.php" class="link">operador ===</a>
 para probar el valor de retorno exacto de esta función.
</p></div>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imagecolorallocatealpha-changelog">
  <h3 class="title">Historial de cambios</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versión</th>
      <th>Descripción</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">image</code> ahora espera una instancia de <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span>;
  anteriormente, se esperaba un <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="literal">gd</code> válido.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imagecolorallocatealpha-examples">
  <h3 class="title">Ejemplos</h3>
  <div class="example" id="example-1">
   <p><strong>Ejemplo #1 Ejemplo de uso de <span class="function"><strong>imagecolorallocatealpha()</strong></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$size </span><span style="color: #007700">= </span><span style="color: #0000BB">300</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$image</span><span style="color: #007700">=</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">$size</span><span style="color: #007700">, </span><span style="color: #0000BB">$size</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// algo para obtener un fondo blanco con un borde negro<br /></span><span style="color: #0000BB">$back </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$border </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagefilledrectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$size </span><span style="color: #007700">- </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$size </span><span style="color: #007700">- </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$back</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagerectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$size </span><span style="color: #007700">- </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$size </span><span style="color: #007700">- </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$border</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$yellow_x </span><span style="color: #007700">= </span><span style="color: #0000BB">100</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$yellow_y </span><span style="color: #007700">= </span><span style="color: #0000BB">75</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$red_x    </span><span style="color: #007700">= </span><span style="color: #0000BB">120</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$red_y    </span><span style="color: #007700">= </span><span style="color: #0000BB">165</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$blue_x   </span><span style="color: #007700">= </span><span style="color: #0000BB">187</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$blue_y   </span><span style="color: #007700">= </span><span style="color: #0000BB">125</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$radius   </span><span style="color: #007700">= </span><span style="color: #0000BB">150</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// asigna colores con valores alpha<br /></span><span style="color: #0000BB">$yellow </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocatealpha</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">75</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$red    </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocatealpha</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">75</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$blue   </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocatealpha</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">75</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Dibuja 3 elipses<br /></span><span style="color: #0000BB">imagefilledellipse</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">$yellow_x</span><span style="color: #007700">, </span><span style="color: #0000BB">$yellow_y</span><span style="color: #007700">, </span><span style="color: #0000BB">$radius</span><span style="color: #007700">, </span><span style="color: #0000BB">$radius</span><span style="color: #007700">, </span><span style="color: #0000BB">$yellow</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagefilledellipse</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">$red_x</span><span style="color: #007700">, </span><span style="color: #0000BB">$red_y</span><span style="color: #007700">, </span><span style="color: #0000BB">$radius</span><span style="color: #007700">, </span><span style="color: #0000BB">$radius</span><span style="color: #007700">, </span><span style="color: #0000BB">$red</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagefilledellipse</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">, </span><span style="color: #0000BB">$blue_x</span><span style="color: #007700">, </span><span style="color: #0000BB">$blue_y</span><span style="color: #007700">, </span><span style="color: #0000BB">$radius</span><span style="color: #007700">, </span><span style="color: #0000BB">$radius</span><span style="color: #007700">, </span><span style="color: #0000BB">$blue</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// No olvidar enviar un header correcto<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type: image/png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// y finalmente, mostrar el resultado<br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$image</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Resultado del ejemplo anterior es similar a:</p></div>
   <div class="mediaobject">
    
    <div class="imageobject">
     <img src="images/21009b70229598c6a80eef8b45bf282b-imagecolorallocatealpha.png" alt="Salida del ejemplo: imagecolorallocatealpha()" width="300" height="300" />
    </div>
   </div>
  </div>

  <div class="example" id="imagecolorallocatealpha.example.convert">
   <p><strong>Ejemplo #2 
    Conversión de valor alpha típico para usarlo con
    <span class="function"><strong>imagecolorallocatealpha()</strong></span>
   </strong></p>
   <div class="example-contents"><p>
    Generalmente los valores alpha <code class="literal">0</code> designan los píxeles
    completamente transparentes, y el canal alpha tiene 8 bits. Para convertir
    tales valores alpha para ser compatibles con
    <span class="function"><strong>imagecolorallocatealpha()</strong></span>, un poco de aritmética simple
    es suficiente:
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$alpha8 </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #FF8000">// completamente transparente<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">127 </span><span style="color: #007700">- (</span><span style="color: #0000BB">$alpha8 </span><span style="color: #007700">&gt;&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$alpha8 </span><span style="color: #007700">= </span><span style="color: #0000BB">255</span><span style="color: #007700">; </span><span style="color: #FF8000">// completamente opaco<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">127 </span><span style="color: #007700">- (</span><span style="color: #0000BB">$alpha8 </span><span style="color: #007700">&gt;&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>El ejemplo anterior mostrará:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">int(127)
int(0)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imagecolorallocatealpha-seealso">
  <h3 class="title">Ver también</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imagecolorallocate.php" class="function" rel="rdfs-seeAlso">imagecolorallocate()</a> - Asigna una coloraci&oacute;n para una imagen</span></li>
   <li><span class="function"><a href="function.imagecolordeallocate.php" class="function" rel="rdfs-seeAlso">imagecolordeallocate()</a> - Elimina un color de una imagen</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>