时间:2021-07-01 10:21:17 帮助过:26人阅读
- <br><?php <br>header("Content-type: image/png"); <br>$im = @imagecreatetruecolor(50, 100) <br>or die("Cannot Initialize new GD image stream"); <br>$text_color = imagecolorallocate($im, 233, 14, 91); <br>imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); <br>imagepng($im); <br>imagedestroy($im); <br>?> <br> <br>Note: 本函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本)。 <br><br><strong>php imagecolorallocatealpha 创建透明图片实例 <br></strong>imagecolorallocatealpha(resource $image , int $red , int $green , int $blue, int $alpha ) <br>imagecolorallocatealpha()的行为相同imagecolorallocate()同阿尔法增加透明度参数。 <br><br><br>$image <br>图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。 <br><br>$red <br>红色分量的价值。 <br><br>$green <br>价值的绿色成分。 <br><br>$blue <br>蓝色成分的价值。 <br><br>$alpha <br>一个介于0和127的价值。 0表示完全不透明,而127表示完全透明。 <br>来看个imagecolorallocatealpha实例教程 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>$size = 300; <br>$image=imagecreatetruecolor($size, $size); <br><br>// something to get a white background with black border <br>$back = imagecolorallocate($image, 255, 255, 255); <br>$border = imagecolorallocate($image, 0, 0, 0); <br>imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back); <br>imagerectangle($image, 0, 0, $size - 1, $size - 1, $border); <br><br>$yellow_x = 100; <br>$yellow_y = 75; <br>$red_x = 120; <br>$red_y = 165; <br>$blue_x = 187; <br>$blue_y = 125; <br>$radius = 150; <br><br>// allocate colors with alpha values <br>$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75); <br>$red = imagecolorallocatealpha($image, 255, 0, 0, 75); <br>$blue = imagecolorallocatealpha($image, 0, 0, 255, 75); <br><br>// drawing 3 overlapped circle <br>imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow); <br>imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red); <br>imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue); <br><br>// don't forget to output a correct header! <br>header('Content-type: image/png'); <br><br>// and finally, output the result <br>imagepng($image); <br>imagedestroy($image); <br>?> <br><br><br><strong>php imagecreatetruecolor创建高清图片函数 <br></strong>imagecreatetruecolor()返回一个图像标识符代表指定大小的黑色形象。 <br><br>根据你的PHP和GD版本中函数定义与否。对于PHP 4.0.6通过4.1.x这个函数总是存在的 <br><br>,如果广东模块加载,但它要求GD2的情况下被安装了PHP将发出一个致命错误并退出。 <br><br>用PHP 4.2.x版这种行为是不同的人发出警告,而不是一个错误。其他版本只定义此功 <br><br>能, <br><br>看看实例 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>header ('Content-type: image/png'); <br>$im = @imagecreatetruecolor(120, 20) <br>or die('Cannot Initialize new GD image stream'); <br>$text_color = imagecolorallocate($im, 233, 14, 91); <br>imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); <br>imagepng($im); <br>imagedestroy($im); <br>?> <br> <br><br>我提出这方面合作 - 结合一些例子,然后动态生成的文本。但是,与此设置,我能得 <br><br>到透明背景的工作也。 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>// Set the content-type <br><br>header('Content-type: image/png'); <br><br>// Create the image <br>$im = imagecreatetruecolor(175, 15); <br>imagesavealpha($im, true); <br><br>// Create some colors <br>$white = imagecolorallocate($im, 255, 255, 255); <br>$grey = imagecolorallocate($im, 128, 128, 128); <br>$black = imagecolorallocate($im, 0, 0, 0); <br>imagefilledrectangle($im, 0, 0, 150, 25, $black); <br>$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127); <br>imagefill($im, 0, 0, $trans_colour); <br><br>// The text to draw <br>$text = $_GET['text']; <br>// Replace path by your own font path <br>$font = 'catriel regular.ttf'; <br><br>// Add some shadow to the text <br>imagettftext($im, 9, 0, 13, 16, $black, $font, $text); <br><br>// Add the text <br>imagettftext($im, 9, 0, 12, 15, $white, $font, $text); <br><br>// Using imagepng() results in clearer text compared with imagejpeg() <br>imagepng($im); <br>imagedestroy($im); <br>?> <br><br><strong>ph利用imagecreatetruecolor动态生成高清图片代码</strong> <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>//实例用我们用imagecreatetruecolor <br>header ('Content-type: image/png'); <br>$im = @imagecreatetruecolor(120, 20) <br>or die('Cannot Initialize new GD image stream'); <br>$text_color = imagecolorallocate($im, 233, 14, 91); <br>imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); <br>imagepng($im); <br>imagedestroy($im); <br><br>//我把这个一起 - 结合较好的例子,然后动态生成的文本。但是,与此成立,我能得到透明背景以及工作。 <br>//实例二imagecreatetruecolor <br>header('Content-type: image/png'); <br><br>// Create the image <br>$im = imagecreatetruecolor(175, 15); <br>imagesavealpha($im, true); <br><br>// Create some colors <br>$white = imagecolorallocate($im, 255, 255, 255); <br>$grey = imagecolorallocate($im, 128, 128, 128); <br>$black = imagecolorallocate($im, 0, 0, 0); <br>imagefilledrectangle($im, 0, 0, 150, 25, $black); <br>$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127); <br>imagefill($im, 0, 0, $trans_colour); <br><br>// The text to draw <br>$text = $_GET['text']; <br>// Replace path by your own font path <br>$font = 'catriel regular.ttf'; <br><br>// Add some shadow to the text <br>imagettftext($im, 9, 0, 13, 16, $black, $font, $text); <br><br>// Add the text <br>imagettftext($im, 9, 0, 12, 15, $white, $font, $text); <br><br>// Using imagepng() results in clearer text compared with imagejpeg() <br>imagepng($im); <br>imagedestroy($im); <br><br>/* <br>实例三创建透明图片 <br><br>如果你想创建一个PNG图像*透明*,其中的背景是完全透明的,所有行动发生在借鉴,除此之外,然后执行下列操作: <br>*/ <br>$png = imagecreatetruecolor(800, 600); <br>imagesavealpha($png, true); <br><br>$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127); <br>imagefill($png, 0, 0, $trans_colour); <br><br>$red = imagecolorallocate($png, 255, 0, 0); <br>imagefilledellips教程e($png, 400, 300, 400, 300, $red); <br><br>header("Content-type: image/png"); <br>imagepng($png); <br> <br>你要做的就是创建一个真正的彩色图像,确保阿尔法保存状态是,然后填写一个颜色,也经历了阿尔法级别设置为完全透明(127)的图像。 <br><br>从上面的代码产生的巴新将有一个完全透明的背景(一红色圆圈拖到Photoshop中的图像,以了解自己) <br>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)</li><li> </li><li> </li></ol></pre></li></ol></pre></li></ol></pre></li></ol></pre>