phpimagecreatetruecolor创建高清和透明图片代码小结
代码 创建 图片 小结 透明 高清
2023-06-13 09:14:18 时间
(PHP4>=4.0.6,PHP5)
imagecreatetruecolor—新建一个真彩色图像
说明
resourceimagecreatetruecolor(int$x_size,int$y_size)
imagecreatetruecolor()返回一个图像标识符,代表了一幅大小为x_size和y_size的黑色图像。
是否定义了本函数取决于PHP和GD的版本。从PHP4.0.6到4.1.x只要加载了GD模块本函数一直存在,但是在没有安装GD2的时候调用,PHP将发出致命错误并退出。在PHP4.2.x中此行为改为发出警告而不是错误。其它版本只在安装了正确的GD版本时定义了本函数。
新建一个新的GD图像流并输出图像
复制代码代码如下:
imagecreatetruecolor—新建一个真彩色图像
说明
resourceimagecreatetruecolor(int$x_size,int$y_size)
imagecreatetruecolor()返回一个图像标识符,代表了一幅大小为x_size和y_size的黑色图像。
是否定义了本函数取决于PHP和GD的版本。从PHP4.0.6到4.1.x只要加载了GD模块本函数一直存在,但是在没有安装GD2的时候调用,PHP将发出致命错误并退出。在PHP4.2.x中此行为改为发出警告而不是错误。其它版本只在安装了正确的GD版本时定义了本函数。
新建一个新的GD图像流并输出图像
<?php
header("Content-type:image/png");
$im=@imagecreatetruecolor(50,100)
ordie("CannotInitializenewGDimagestream");
$text_color=imagecolorallocate($im,233,14,91);
imagestring($im,1,5,5,"ASimpleTextString",$text_color);
imagepng($im);
imagedestroy($im);
?>
Note:本函数需要GD2.0.1或更高版本(推荐2.0.28及更高版本)。
phpimagecolorallocatealpha创建透明图片实例
imagecolorallocatealpha(resource$image,int$red,int$green,int$blue,int$alpha)
imagecolorallocatealpha()的行为相同imagecolorallocate()同阿尔法增加透明度参数。
$image
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。
$red
红色分量的价值。
$green
价值的绿色成分。
$blue
蓝色成分的价值。
$alpha
一个介于0和127的价值。0表示完全不透明,而127表示完全透明。
来看个imagecolorallocatealpha实例教程
<?php
$size=300;
$image=imagecreatetruecolor($size,$size);
//somethingtogetawhitebackgroundwithblackborder
$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;
//allocatecolorswithalphavalues
$yellow=imagecolorallocatealpha($image,255,255,0,75);
$red=imagecolorallocatealpha($image,255,0,0,75);
$blue=imagecolorallocatealpha($image,0,0,255,75);
//drawing3overlappedcircle
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"tforgettooutputacorrectheader!
header("Content-type:image/png");
//andfinally,outputtheresult
imagepng($image);
imagedestroy($image);
?>
phpimagecreatetruecolor创建高清图片函数
imagecreatetruecolor()返回一个图像标识符代表指定大小的黑色形象。
根据你的PHP和GD版本中函数定义与否。对于PHP4.0.6通过4.1.x这个函数总是存在的
,如果广东模块加载,但它要求GD2的情况下被安装了PHP将发出一个致命错误并退出。
用PHP4.2.x版这种行为是不同的人发出警告,而不是一个错误。其他版本只定义此功
能,
看看实例
<?php
header("Content-type:image/png");
$im=@imagecreatetruecolor(120,20)
ordie("CannotInitializenewGDimagestream");
$text_color=imagecolorallocate($im,233,14,91);
imagestring($im,1,5,5,"ASimpleTextString",$text_color);
imagepng($im);
imagedestroy($im);
?>
我提出这方面合作-结合一些例子,然后动态生成的文本。但是,与此设置,我能得
到透明背景的工作也。
<?php
//Setthecontent-type
header("Content-type:image/png");
//Createtheimage
$im=imagecreatetruecolor(175,15);
imagesavealpha($im,true);
//Createsomecolors
$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);
//Thetexttodraw
$text=$_GET["text"];
//Replacepathbyyourownfontpath
$font="catrielregular.ttf";
//Addsomeshadowtothetext
imagettftext($im,9,0,13,16,$black,$font,$text);
//Addthetext
imagettftext($im,9,0,12,15,$white,$font,$text);
//Usingimagepng()resultsinclearertextcomparedwithimagejpeg()
imagepng($im);
imagedestroy($im);
?>
ph利用imagecreatetruecolor动态生成高清图片代码
//实例用我们用imagecreatetruecolor
header("Content-type:image/png");
$im=@imagecreatetruecolor(120,20)
ordie("CannotInitializenewGDimagestream");
$text_color=imagecolorallocate($im,233,14,91);
imagestring($im,1,5,5,"ASimpleTextString",$text_color);
imagepng($im);
imagedestroy($im);
//我把这个一起-结合较好的例子,然后动态生成的文本。但是,与此成立,我能得到透明背景以及工作。
//实例二imagecreatetruecolor
header("Content-type:image/png");
//Createtheimage
$im=imagecreatetruecolor(175,15);
imagesavealpha($im,true);
//Createsomecolors
$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);
//Thetexttodraw
$text=$_GET["text"];
//Replacepathbyyourownfontpath
$font="catrielregular.ttf";
//Addsomeshadowtothetext
imagettftext($im,9,0,13,16,$black,$font,$text);
//Addthetext
imagettftext($im,9,0,12,15,$white,$font,$text);
//Usingimagepng()resultsinclearertextcomparedwithimagejpeg()
imagepng($im);
imagedestroy($im);
/*
实例三创建透明图片
如果你想创建一个PNG图像*透明*,其中的背景是完全透明的,所有行动发生在借鉴,除此之外,然后执行下列操作:
*/
$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教程e($png,400,300,400,300,$red);
header("Content-type:image/png");
imagepng($png);
你要做的就是创建一个真正的彩色图像,确保阿尔法保存状态是,然后填写一个颜色,也经历了阿尔法级别设置为完全透明(127)的图像。
从上面的代码产生的巴新将有一个完全透明的背景(一红色圆圈拖到Photoshop中的图像,以了解自己)
TheresultingPNGfromthecodeabovewillhavearedcircleonafullytransparentbackground(dragtheimageintoPhotoshoptoseeforyourself)
相关文章
- 用代码制作一个爱心表白_简单的代码表白跳动的爱心
- 如何用 ABAP 代码创建 SAP CRM IBase
- POT超阈值模型和极值理论EVT分析|附代码数据
- 【鸿蒙 HarmonyOS】创建 Java 语言 HarmonyOS 手机应用 ( 首次进入 DevEco Studio 配置环境 | 创建 Java 手机工程 | 鸿蒙工程代码目录简介 )
- 【鸿蒙 HarmonyOS】界面跳转 ( Page Ability 的 action 标识 | Page Ability 之间的界面跳转及传递数据 | 鸿蒙工程下创建 Module | 代码示例 )
- 终结扩散模型:OpenAI开源新模型代码,一步成图,1秒18张
- 代码Oracle数据库实现分页技术的指南(oracle写分页)
- Oracle代码窗口中解决换行问题(oracle代码窗口换行)
- js装载xml文件然后发向服务器的实现代码
- C#TreeView控件使用代码
- PHP将图片按创建时间进行分类存储的实现代码
- php!function_exists("T7FC56270E7A70FA81A5935B72EACBE29"))代码解密
- php利用cookie实现访问次数统计代码
- php递归创建和删除文件夹的代码小结
- javascript设置金额样式转换保留两位小数示例代码
- 5种PHP创建数组的实例代码分享
- PHP获取本周第一天和最后一天示例代码
- 在Mysql上创建数据表实例代码
- 简单的js图片轮换代码(js图片轮播)