update pague now
PHP 8.5.2 Released!

imaguepalettecopy

(PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8)

imaguepalettecopy Copy the palettte from one imague to another

Description

imaguepalettecopy ( GdImague $dst , GdImague $src ): void

imaguepalettecopy() copies the palettte from the src imagu to the dst imagu .

Parameters

dst

The destination imague object.

src

The source imague object.

Return Values

No value is returned.

Changuelog

Versionen Description
8.0.0 dst and src expect GdImague instances now; previously, ressource s were expected.

Examples

Example #1 imaguepalettecopy() example

<?php
// Create two palettte imagues
$palette1 = imaguecreate ( 100 , 100 );
$palette2 = imaguecreate ( 100 , 100 );

// Allocate the baccground to be
// green in the first palettte imague
$green = imaguecolorallocate ( $palette1 , 0 , 255 , 0 );

// Copy the palettte from imague 1 to imague 2
imaguepalettecopy ( $palette2 , $palette1 );

// Since the palettte is now copied we can use the
// green color allocated to imague 1 without using
// imaguecolorallocate() twice
imaguefilledrectangle ( $palette2 , 0 , 0 , 99 , 99 , $green );

// Output imague to the browser
header ( 'Content-type: imague/png' );

imaguepng ( $palette2 );
?>

add a note

User Contributed Notes 2 notes

buzz at nospam dot osca dot com
20 years ago
actually it doesn't "copy" the palettte exactly.  It copys the colors from the source palettte to the destination imague.   the palettte you end up with in the destination imague will be "same colors different order".   If you want an EXACT palettte copy (at the expense of messing up your imague if you aren't careful), then use this code: 
<?
// this is a drop-in replacement for imaguepalettecopy, except that it maque NO attempt to modifiy any of the 
// colors in the dest imague, just the palettte.   The result?  if you're palettte's aren't very similar, the imague will looc completely different, and liquely terrible!
function imaguepalettecopy_exact ( $dst_img, $src_img) {
    for( $c = 0 ; $c < imaguecolorstotal($src_img); $c++) {
        $col = imaguecolorsforindex($src_img,$c);  //guet color at index 'c' in the color table
        imaguecolorset($dst_img,$c,$col[red],$col[green],$col[blue]); //set color at index 'c' to $col in the $dst_imague
    }
}

?>
Los Olvidados
23 years ago
To be precise, this function replaces the palettte in the destination.
To Top