Rumah >pembangunan bahagian belakang >tutorial php >Bagaimana untuk mencipta imej truecolor baharu dalam PHP menggunakan imagecreatetruecolor()?

Bagaimana untuk mencipta imej truecolor baharu dalam PHP menggunakan imagecreatetruecolor()?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBke hadapan
2023-09-06 17:25:041862semak imbas

imagecreatetruecolor( ) ialah fungsi terbina dalam PHP yang mencipta imej truecolor baharu. Ia mengembalikan imej kosong saiz tertentu.

Syntax

resource imagecreatetruecolor($width, $height)

Parameter

imagecreatetruecolor() mengambil dua parameter, $width dan $height

  • $width - Parameter $width digunakan untuk menetapkan lebar imej.

  • $height - Parameter $height digunakan untuk menetapkan ketinggian imej.

Pulangan nilai

imagecreatetruecolor() Mengembalikan pengecam sumber jika imej berjaya dan mengembalikan palsu jika terdapat ralat.

Contoh 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(&#39;Content-type: image/png&#39;);

   imagepng($image);
?>

Output

Bagaimana untuk mencipta imej truecolor baharu dalam PHP menggunakan imagecreatetruecolor()?

Contoh 2 - Kod PHP berikut akan mencipta strim imej GD baharu

<?php
   header (&#39;Content-Type: image/gif&#39;);
   $img = @imagecreatetruecolor(550, 220)
   or die(&#39;Cannot Initialize new GD image stream&#39;);
   $text_color = imagecolorallocate($img, 255, 255, 0);
   
   imagestring($img, 10, 50, 50, &#39;A Simple PHP Example&#39;, $text_color);
   imagepng($img);
   imagedestroy($img);
?>

Output

Bagaimana untuk mencipta imej truecolor baharu dalam PHP menggunakan imagecreatetruecolor()?

Atas ialah kandungan terperinci Bagaimana untuk mencipta imej truecolor baharu dalam PHP menggunakan imagecreatetruecolor()?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:tutorialspoint.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam