PHP
 Computer >> コンピューター >  >> プログラミング >> PHP

PHPのimagepalettecopy()関数を使用して、ある画像から別の画像にパレットをコピーするにはどうすればよいですか?


imagepalettecopy() は、ある画像から別の画像にパレットをコピーするために使用される組み込みのPHP関数です。この関数は、パレットをソース画像から宛先画像にコピーします。

構文

void imagepalettecopy(resource $destination, resource $source)

パラメータ

imagepalettecopy() 2つのパラメータを受け入れます-$source および$destination

  • $ destination −宛先画像リソースを指定します。

  • $ source −ソース画像リソースを指定します。

戻り値

imagepalettecopy() 値を再調整しません。

例1

<?php
   // Create two palette images using imagecreate() function.
   $palette1 = imagecreate(700, 300);
   $palette2 = imagecreate(700, 300);
   
   // Allocate the background to be
   // gray in the first palette image
   $gray = imagecolorallocate($palette1, 122, 122, 122);

   // Copy the palette from image 1 to image 2
   imagepalettecopy($palette2, $palette1);

   // gray color allocated to image 1 without using
   // imagecolorallocate() twice
   imagefilledrectangle($palette2, 0, 0, 99, 99, $gray);

   // Output image to the browser
   header('Content-type: image/png');
   imagepng($palette2);
   imagedestroy($palette1);
   imagedestroy($palette2);
?>

出力

PHPのimagepalettecopy()関数を使用して、ある画像から別の画像にパレットをコピーするにはどうすればよいですか?

例2

<?php
   // Created two palette images using imagecreate() function.
   $palette1 = imagecreate(500, 200);
   $palette2 = imagecreate(500, 200);

   // Create a gray color
   $gray= imagecolorallocate($palette1, 0, 255, 0);

   // gray color as the background to palette 1
   imagefilledrectangle($palette1, 0, 0, 99, 99, $gray);

   // Copy the palette from image 1 to image 2
   imagepalettecopy($palette2, $palette1);

   // Get the number of colors in the image
   $color1 = imagecolorstotal($palette1);
   $color2 = imagecolorstotal($palette2);
   
   echo "Colors in image 1 are " . $color1 . "<br>";
   echo "Colors in image 2 is " . $color2;
?>

出力

Colors in image 1 are 1
Colors in image 2 are 1

  1. PHPのimagecreatefrompng()関数を使用してPNGファイルまたはURLから新しい画像を作成するにはどうすればよいですか?

    PHPでは、 imagecreatefrompng() PNGファイルまたはURLから新しい画像を作成するために使用される組み込み関数です。 imagecreatefrompng() 指定されたファイル名から取得した画像を表す画像識別子を返します。 構文 resource imagecreatefrompng(string $filename) パラメータ imagecreatefrompng() $filenameという1つのパラメーターのみを取ります。このパラメータは、画像の名前またはPNG画像へのパスを保持します。 戻り値 imagecreatefrompng()は、成功すると画

  2. PHPのimagecreatefromjpeg()関数を使用してJPEGファイルから新しい画像を作成するにはどうすればよいですか?

    imagecreatefromjpeg() は、JPEGファイルから新しい画像を作成するために使用されるPHPの組み込み関数です。指定されたファイル名から取得した画像を表す画像識別子を返します。 構文 resource imagecreatefromjpeg(string $filename) パラメータ imagecreatefromjpeg() $ filenameという1つのパラメータのみを使用します 、画像の名前またはJPEG画像へのパスを保持します。 戻り値 imagecreatefromjpeg() 成功すると画像リソース識別子を返し、falseではエラーを返します。 例