PHP imagecreatetruecolor creates a high resolution and transparent image code summary
- 2020-03-31 20:45:45
- OfStack
(PHP 4 > = 4.0.6, PHP 5)
Imagecreatetruecolor - create a new truecolor image
instructions
Resource imagecreatetruecolor (int $x_size, int $y_size)
Imagecreatetruecolor () returns an image identifier representing a black image of x_size and y_size.
Whether or not this function is defined depends on the versions of PHP and GD. From PHP 4.0.6 to 4.1.x this function exists as long as GD module is loaded, but when called without GD2 installed, PHP will issue a fatal error and exit. In PHP 4.2.x this behavior is changed to issue a warning instead of an error. Other versions define this function only when the correct GD version is installed.
Create a new GD image stream and output the image
Note: this function requires GD 2.0.1 or later (2.0.28 or later is recommended).
PHP imagecolorallocatealpha creates a transparent image instance
Imagecolorallocatealpha (resource $image, int $red, int $green, int $blue, int $alpha)
Imagecolorallocatealpha () behaves the same imagecolorallocate () as alpha does to increase the transparency parameter.
$image
Image resources through the creation of image features, such as, a return to imagecreatetruecolor ().
$red
The value of the red component.
$green,
The value of the green component.
$blue
The value of the blue component.
$alpha
A value between 0 and 127. 0 means completely opaque, and 127 means completely transparent.
Take a look at an example tutorial on imagecolorallocatealpha
PHP imagecreatetruecolor to create hd image function
Imagecreatetruecolor () returns an image identifier representing the specified size of the black image.
Depending on your PHP and GD version of the function definition or not. For PHP 4.0.6 the function 4.1.x always exists
If the guangdong module loads but it requires GD2 to be installed under the case of PHP it will issue a fatal error and exit.
This behavior with PHP 4.2.x is a warning from a different person, not an error. Other versions define this work only
Can,
Look at the instance of
I present this aspect of collaboration - combining some examples and then dynamically generating the text. However, with this setting, I can get
To the transparent background work also.
Ph USES imagecreatetruecolor to dynamically generate hd image code
All you have to do is create a true color image, make sure the alpha save state is, and then fill in a color that also goes through the alpha level setting to fully transparent (127) image.
The PNG generated from the above code will have a completely transparent background (a red circle dragged into the image in Photoshop to learn about itself)
The resulting PNG from The code above will have a red circle on a fully transparent background (drag The image into Photoshop to see for yourself)
Imagecreatetruecolor - create a new truecolor image
instructions
Resource imagecreatetruecolor (int $x_size, int $y_size)
Imagecreatetruecolor () returns an image identifier representing a black image of x_size and y_size.
Whether or not this function is defined depends on the versions of PHP and GD. From PHP 4.0.6 to 4.1.x this function exists as long as GD module is loaded, but when called without GD2 installed, PHP will issue a fatal error and exit. In PHP 4.2.x this behavior is changed to issue a warning instead of an error. Other versions define this function only when the correct GD version is installed.
Create a new GD image stream and output the image
<?php
header("Content-type: image/png");
$im = @imagecreatetruecolor(50, 100)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
Note: this function requires GD 2.0.1 or later (2.0.28 or later is recommended).
PHP imagecolorallocatealpha creates a transparent image instance
Imagecolorallocatealpha (resource $image, int $red, int $green, int $blue, int $alpha)
Imagecolorallocatealpha () behaves the same imagecolorallocate () as alpha does to increase the transparency parameter.
$image
Image resources through the creation of image features, such as, a return to imagecreatetruecolor ().
$red
The value of the red component.
$green,
The value of the green component.
$blue
The value of the blue component.
$alpha
A value between 0 and 127. 0 means completely opaque, and 127 means completely transparent.
Take a look at an example tutorial on imagecolorallocatealpha
<?php
$size = 300;
$image=imagecreatetruecolor($size, $size);
// something to get a white background with black border
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
imagerectangle($image, 0, 0, $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($image, 255, 255, 0, 75);
$red = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
// 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);
?>
PHP imagecreatetruecolor to create hd image function
Imagecreatetruecolor () returns an image identifier representing the specified size of the black image.
Depending on your PHP and GD version of the function definition or not. For PHP 4.0.6 the function 4.1.x always exists
If the guangdong module loads but it requires GD2 to be installed under the case of PHP it will issue a fatal error and exit.
This behavior with PHP 4.2.x is a warning from a different person, not an error. Other versions define this work only
Can,
Look at the instance of
<?php
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
I present this aspect of collaboration - combining some examples and then dynamically generating the text. However, with this setting, I can get
To the transparent background work also.
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';
// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);
// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
Ph USES imagecreatetruecolor to dynamically generate hd image code
//For example we use imagecreatetruecolor
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
//I took this together -- combined with better examples, and then dynamically generated text. However, with this set up, I can get a transparent background as well as work.
//Example 2 imagecreatetruecolor
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';
// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);
// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
$png = imagecreatetruecolor(800, 600);
imagesavealpha($png, true);
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
imagefill($png, 0, 0, $trans_colour);
$red = imagecolorallocate($png, 255, 0, 0);
imagefilledellips The tutorial e($png, 400, 300, 400, 300, $red);
header("Content-type: image/png");
imagepng($png);
All you have to do is create a true color image, make sure the alpha save state is, and then fill in a color that also goes through the alpha level setting to fully transparent (127) image.
The PNG generated from the above code will have a completely transparent background (a red circle dragged into the image in Photoshop to learn about itself)
The resulting PNG from The code above will have a red circle on a fully transparent background (drag The image into Photoshop to see for yourself)