imagecolorallocatealpha

(PHP 4 >= 4.3.2, PHP 5, PHP 7)

imagecolorallocatealpha为一锟斤拷图锟斤拷锟斤拷锟斤拷锟缴� + alpha

说锟斤拷

imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha ) : int

imagecolorallocatealpha() 锟斤拷锟斤拷为锟斤拷 imagecolorallocate() 锟斤拷同锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟酵革拷锟斤拷炔锟斤拷锟� alpha锟斤拷锟斤拷值锟斤拷 0 锟斤拷 127锟斤拷0 锟斤拷示锟斤拷全锟斤拷透锟斤拷锟斤拷127 锟斤拷示锟斤拷全透锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷锟绞э拷锟斤拷蚍祷锟� FALSE锟斤拷

Example #1 使锟斤拷 imagecolorallocatealpha() 锟斤拷锟斤拷锟斤拷

<?php
$size 
300;
$image=imagecreatetruecolor($size$size);

// 锟矫帮拷色锟斤拷锟斤拷锟接猴拷色锟竭框画革拷锟斤拷锟斤拷
$back imagecolorallocate($image255255255);
$border imagecolorallocate($image000);
imagefilledrectangle($image00$size 1$size 1$back);
imagerectangle($image00$size 1$size 1$border);

$yellow_x 100;
$yellow_y 75;
$red_x    120;
$red_y    165;
$blue_x   187;
$blue_y   125;
$radius   150;

// 锟斤拷 alpha 值锟斤拷锟斤拷一些锟斤拷色
$yellow imagecolorallocatealpha($image255255075);
$red    imagecolorallocatealpha($image2550075);
$blue   imagecolorallocatealpha($image0025575);

// 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷圆
imagefilledellipse($image$yellow_x$yellow_y$radius$radius$yellow);
imagefilledellipse($image$red_x$red_y$radius$radius$red);
imagefilledellipse($image$blue_x$blue_y$radius$radius$blue);

// 锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷锟饺凤拷锟� header锟斤拷
header('Content-type: image/png');

// 锟斤拷锟斤拷锟斤拷锟斤拷锟�
imagepng($image);
imagedestroy($image);
?>

Note: 锟剿猴拷锟斤拷锟斤拷要 GD 2.0.1 锟斤拷锟斤拷甙姹�(锟狡硷拷 2.0.28 锟斤拷锟斤拷锟竭版本)锟斤拷

锟轿硷拷 imagecolorallocate() 锟斤拷 imagecolordeallocate()锟斤拷

锟斤拷锟斤拷

image

锟斤拷图锟襟创斤拷锟斤拷锟斤拷(锟斤拷锟斤拷imagecreatetruecolor())锟斤拷锟截碉拷图锟斤拷锟斤拷源锟斤拷

red

锟斤拷色锟缴分碉拷值锟斤拷

green

锟斤拷色锟缴分碉拷值锟斤拷

blue

锟斤拷色锟缴分碉拷值锟斤拷

alpha

A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent.

The colors parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF.

锟斤拷锟斤拷值

A color identifier or FALSE if the allocation failed.

Warning

锟剿猴拷锟斤拷锟斤拷锟杰凤拷锟截诧拷锟斤拷值 FALSE锟斤拷锟斤拷也锟斤拷锟杰凤拷锟截碉拷同锟斤拷 FALSE 锟侥非诧拷锟斤拷值锟斤拷锟斤拷锟侥讹拷 锟斤拷锟斤拷锟斤拷锟斤拷锟铰斤拷锟皆伙拷取锟斤拷锟斤拷锟斤拷息锟斤拷应使锟斤拷 === 锟斤拷锟斤拷锟�锟斤拷锟斤拷锟皆此猴拷锟斤拷锟侥凤拷锟斤拷值锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
Prior to 5.1.3 Returns -1 if the allocation failed.

锟斤拷锟斤拷

Example #2 Example of using imagecolorallocatealpha()

<?php
$size 
300;
$image=imagecreatetruecolor($size$size);

// something to get a white background with black border
$back imagecolorallocate($image255255255);
$border imagecolorallocate($image000);
imagefilledrectangle($image00$size 1$size 1$back);
imagerectangle($image00$size 1$size 1$border);

$yellow_x 100;
$yellow_y 75;
$red_x    120;
$red_y    165;
$blue_x   187;
$blue_y   125;
$radius   150;

// allocate colors with alpha values
$yellow imagecolorallocatealpha($image255255075);
$red    imagecolorallocatealpha($image2550075);
$blue   imagecolorallocatealpha($image0025575);

// drawing 3 overlapped circle
imagefilledellipse($image$yellow_x$yellow_y$radius$radius$yellow);
imagefilledellipse($image$red_x$red_y$radius$radius$red);
imagefilledellipse($image$blue_x$blue_y$radius$radius$blue);

// don't forget to output a correct header!
header('Content-Type: image/png');

// and finally, output the result
imagepng($image);
imagedestroy($image);
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

Output of example : Example of using imagecolorallocatealpha()

注锟斤拷

Note: 锟剿猴拷锟斤拷锟斤拷要 GD 2.0.1 锟斤拷锟斤拷甙姹�(锟狡硷拷 2.0.28 锟斤拷锟斤拷锟竭版本)锟斤拷

锟轿硷拷