imagecreatetruecolor()を使用してPHPで新しいトゥルーカラー画像を作成するにはどうすればよいですか?
imagecreatetruecolor() は、新しいトゥルーカラー画像を作成するために使用されるPHPの組み込み関数です。指定されたサイズの空白の画像を返します。
構文
resource imagecreatetruecolor($width, $height)
パラメータ
imagecreatetruecolor() $ widthの2つのパラメータを取ります および$height 。
-
$ width −$widthパラメータは画像の幅を設定するために使用されます。
-
$ height − $ heightパラメーターは、画像の高さを設定するために使用されます。
戻り値
imagecreatetruecolor() 成功した場合は画像リソース識別子を返し、エラーの場合はfalseを返します。
例1
<?php
// Set the vertices of polygon
$values = array(
150, 50, // Point 1 (x, y)
50, 250, // Point 2 (x, y)
250, 250 // Point 3 (x, y)
);
// Create the size of image or blank image
$image = imagecreatetruecolor(700, 350);
// Set the background color of image
$background_color = imagecolorallocate($image, 122, 122, 122);
// Fill background with above selected color
imagefill($image, 0, 0, $background_color);
// Allocate a color for the polygon
$image_color = imagecolorallocate($image, 0, 255, 255);
// Draw the polygon
imagepolygon($image, $values, 3, $image_color);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($image);
?> 出力
例2-以下のPHPコードは、新しいGDイメージストリームを作成します
<?php
header ('Content-Type: image/gif');
$img = @imagecreatetruecolor(550, 220)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($img, 255, 255, 0);
imagestring($img, 10, 50, 50, 'A Simple PHP Example', $text_color);
imagepng($img);
imagedestroy($img);
?> 出力
-
PHPのimagecreatefromjpeg()関数を使用してJPEGファイルから新しい画像を作成するにはどうすればよいですか?
imagecreatefromjpeg() は、JPEGファイルから新しい画像を作成するために使用されるPHPの組み込み関数です。指定されたファイル名から取得した画像を表す画像識別子を返します。 構文 resource imagecreatefromjpeg(string $filename) パラメータ imagecreatefromjpeg() $ filenameという1つのパラメータのみを使用します 、画像の名前またはJPEG画像へのパスを保持します。 戻り値 imagecreatefromjpeg() 成功すると画像リソース識別子を返し、falseではエラーを返します。 例
-
Java OpenCVライブラリを使用してミラーイメージを作成するにはどうすればよいですか?
鏡像を作成するには ImageIO.read()メソッドを使用して必要な画像を読み取ります。 画像の高さと幅を取得します。 結果を保存するために空のバッファリングされた画像を作成します ネストされたforループを使用すると、画像の各ピクセルをトラバースします。 画像の幅を右から左に繰り返します。 getRGB()メソッドを使用してピクセル値を取得します。 setRGB()メソッドを使用して、新しい幅の値を置き換えて、ピクセル値を結果の画像オブジェクトに設定します。 例 import java.io.File; import java.io.IOEx