downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagepng> <imageloadfont
[edit] Last updated: Fri, 25 May 2012

view this page in

imagepalettecopy

(PHP 4 >= 4.0.1, PHP 5)

imagepalettecopyCopiar la paleta de una imagen a otra

Descripción

void imagepalettecopy ( resource $destination , resource $source )

imagepalettecopy() copia la paleta de la imagen source a la imagen destination.

Parámetros

destination

El recurso de imagen de destino.

source

El recurso de imagen de origen.

Valores devueltos

No devuelve ningún valor.

Ejemplos

Ejemplo #1 Ejemplo de imagepalettecopy()

<?php
// Crear dos imágenes de paleta
$paleta1 imagecreate(100100);
$paleta2 imagecreate(100100);

// Asignar verde al fondo
// en la primera imagen de paleta
$verde imagecolorallocate($paleta102550);

// Copiar la paleta de la imagen 1 a la imagen 2
imagepalettecopy($paleta2$paleta1);

// Ya que la paleta ha sido copiada podemos usar el
// color verde asignado a la imagen 1 sin usar
// imagecolorallocate() dos veces
imagefilledrectangle($paleta2009999$verde);

// Imprimir la imagen en el navegdor
header('Content-type: image/png');

imagepng($paleta2);
imagedestroy($paleta1);
imagedestroy($paleta2);
?>



add a note add a note User Contributed Notes imagepalettecopy
buzz at nospam dot oska dot com 20-Oct-2005 04:51
actually it doesn't "copy" the palette exactly.  It copys the colors from the source palette to the destination image.   the palette you end up with in the destination image will be "same colors different order".   If you want an EXACT palette copy (at the expense of messing up your image if you aren't careful), then use this code:
<?
// this is a drop-in replacement for imagepalettecopy, except that it make NO attempt to modifiy any of the
// colors in the dest image, just the palette.   The result?  if you're palette's aren't very similar, the image will look completely different, and likely terrible!
function imagepalettecopy_exact ( $dst_img, $src_img) {
    for( $c = 0 ; $c < imagecolorstotal($src_img); $c++) {
        $col = imagecolorsforindex($src_img,$c);  //get color at index 'c' in the color table
        imagecolorset($dst_img,$c,$col[red],$col[green],$col[blue]); //set color at index 'c' to $col in the $dst_image
    }
}

?>
Los Olvidados 09-Jan-2003 04:55
To be precise, this function replaces the palette in the destination.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites