⑴ php在图片上添加文字,大神们看看哪里出错了提示我:图像因为出错,无法显示。如下图
你上面生成的jpeg,
下面用png输出不太妥当吧
imagejpeg()
⑵ php如何实现让加入图片的文字居中
如果使用的是GD库,可以使用这个函数写字符串
boolimagestring(resource$image,int$font,int$x,int$y,string$s,int$col)
⑶ php如何生成加粗或者斜体的文字样式图片
加粗或者斜体的文字可以用php的函数控制.我想你是想生成验证码图片是吗?
如果是想生成验证么图片有几个函数可以考虑
imagecreate($length,$height)创建图片.参数是图片的宽度和高度
imagecolorallocate($image,$r,$g,$b)设置背景色,r b g就是图片的三色rgb参数.这个可以由传入0-255的随机数决定随机的背景色.还可以生成字体色
imagettftext($_image,$fontSize,mt_rand(-40,70),$codeNX,$fontSize*1.5,$_color,$ttf,$code[$i]);写入随机的文字,这里要一个字一个字写.所以这个函数要循环调用.
网络了一下 找到了一个类...如下
<?php
/**
*安全验证码
*
*安全的验证码要:验证码文字扭曲、旋转,使用不同字体,添加干扰码。
*如果用中文做验证码(我这里不是哦,有兴趣你来改成用中文的),安全度会更好些,但验证码扭曲和旋转是王道,用了字体也算是已经给字体扭曲了,我就不再去给他添一只扭曲的足了。
*可配置的属性都是一些简单直观的变量,我就不用弄一堆的setter/getter了
*
*@author流水孟春<cmpan(at)qq.com>
*@rightNEWBSD
*@linkhttp://labs.yulans.cn/YL_Security_Secoder
*@linkhttp://wiki.yulans.cn/docs/yl/security/secoder
*/
classYL_Security_Secoder{
/**
*验证码的session的下标
*
*@varstring
*/
publicstatic$seKey='sid.sekey.ylans.cn';
publicstatic$expire=3000;//验证码过期时间(s)
/**
*验证码中使用的字符,01IO容易混淆,建议不用
*
*@varstring
*/
publicstatic$codeSet='346789ABCDEFGHJKLMNPQRTUVWXY';
publicstatic$fontSize=25;//验证码字体大小(px)
publicstatic$useCurve=true;//是否画混淆曲线
publicstatic$useNoise=true;//是否添加杂点
publicstatic$imageH=0;//验证码图片宽
publicstatic$imageL=0;//验证码图片长
publicstatic$length=4;//验证码位数
publicstatic$bg=array(243,251,254);//背景
protectedstatic$_image=null;//验证码图片实例
protectedstatic$_color=null;//验证码字体颜色
/**
*输出验证码并把验证码的值保存的session中
*验证码保存到session的格式为:$_SESSION[self::$seKey]=array('code'=>'验证码值','time'=>'验证码创建时间');
*/
publicstaticfunctionentry(){
//图片宽(px)
self::$imageL||self::$imageL=self::$length*self::$fontSize*1.5+self::$fontSize*1.5;
//图片高(px)
self::$imageH||self::$imageH=self::$fontSize*2;
//建立一幅self::$imageLxself::$imageH的图像
self::$_image=imagecreate(self::$imageL,self::$imageH);
//设置背景
imagecolorallocate(self::$_image,self::$bg[0],self::$bg[1],self::$bg[2]);
//验证码字体随机颜色
self::$_color=imagecolorallocate(self::$_image,mt_rand(1,120),mt_rand(1,120),mt_rand(1,120));
//验证码使用随机字体
$ttf=dirname(__FILE__).'/ttfs/'.mt_rand(1,20).'.ttf';
if(self::$useNoise){
//绘杂点
self::_writeNoise();
}
if(self::$useCurve){
//绘干扰线
self::_writeCurve();
}
//绘验证码
$code=array();//验证码
$codeNX=0;//验证码第N个字符的左边距
for($i=0;$i<self::$length;$i++){
$code[$i]=self::$codeSet[mt_rand(0,27)];
$codeNX+=mt_rand(self::$fontSize*1.2,self::$fontSize*1.6);
//写一个验证码字符
imagettftext(self::$_image,self::$fontSize,mt_rand(-40,70),$codeNX,self::$fontSize*1.5,self::$_color,$ttf,$code[$i]);
}
//保存验证码
isset($_SESSION)||session_start();
$_SESSION[self::$seKey]['code']=join('',$code);//把校验码保存到session
$_SESSION[self::$seKey]['time']=time();//验证码创建时间
header('Cache-Control:private,max-age=0,no-store,no-cache,must-revalidate');
header('Cache-Control:post-check=0,pre-check=0',false);
header('Pragma:no-cache');
header("content-type:image/png");
//输出图像
imagepng(self::$_image);
imagedestroy(self::$_image);
}
/**
*画一条由两条连在一起构成的随机正弦函数曲线作干扰线(你可以改成更帅的曲线函数)
*
*高中的数学公式咋都忘了涅,写出来
* 正弦型函数解析式:y=Asin(ωx+φ)+b
*各常数值对函数图像的影响:
*A:决定峰值(即纵向拉伸压缩的倍数)
*b:表示波形在Y轴的位置关系或纵向移动距离(上加下减)
*φ:决定波形与X轴位置关系或横向移动距离(左加右减)
*ω:决定周期(最小正周期T=2π/∣ω∣)
*
*/
protectedstaticfunction_writeCurve(){
$A=mt_rand(1,self::$imageH/2);//振幅
$b=mt_rand(-self::$imageH/4,self::$imageH/4);//Y轴方向偏移量
$f=mt_rand(-self::$imageH/4,self::$imageH/4);//X轴方向偏移量
$T=mt_rand(self::$imageH*1.5,self::$imageL*2);//周期
$w=(2*M_PI)/$T;
$px1=0;//曲线横坐标起始位置
$px2=mt_rand(self::$imageL/2,self::$imageL*0.667);//曲线横坐标结束位置
for($px=$px1;$px<=$px2;$px=$px+0.9){
if($w!=0){
$py=$A*sin($w*$px+$f)+$b+self::$imageH/2;//y=Asin(ωx+φ)+b
$i=(int)((self::$fontSize-6)/4);
while($i>0){
imagesetpixel(self::$_image,$px+$i,$py+$i,self::$_color);//这里画像素点比imagettftext和imagestring性能要好很多
$i--;
}
}
}
$A=mt_rand(1,self::$imageH/2);//振幅
$f=mt_rand(-self::$imageH/4,self::$imageH/4);//X轴方向偏移量
$T=mt_rand(self::$imageH*1.5,self::$imageL*2);//周期
$w=(2*M_PI)/$T;
$b=$py-$A*sin($w*$px+$f)-self::$imageH/2;
$px1=$px2;
$px2=self::$imageL;
for($px=$px1;$px<=$px2;$px=$px+0.9){
if($w!=0){
$py=$A*sin($w*$px+$f)+$b+self::$imageH/2;//y=Asin(ωx+φ)+b
$i=(int)((self::$fontSize-8)/4);
while($i>0){
imagesetpixel(self::$_image,$px+$i,$py+$i,self::$_color);//这里(while)循环画像素点比imagettftext和imagestring用字体大小一次画出(不用这while循环)性能要好很多
$i--;
}
}
}
}
/**
*画杂点
*往图片上写不同颜色的字母或数字
*/
protectedstaticfunction_writeNoise(){
for($i=0;$i<10;$i++){
//杂点颜色
$noiseColor=imagecolorallocate(
self::$_image,
mt_rand(150,225),
mt_rand(150,225),
mt_rand(150,225)
);
for($j=0;$j<5;$j++){
//绘杂点
imagestring(
self::$_image,
5,
mt_rand(-10,self::$imageL),
mt_rand(-10,self::$imageH),
self::$codeSet[mt_rand(0,27)],//杂点文本为随机的字母或数字
$noiseColor
);
}
}
}
/**
*验证验证码是否正确
*
*@paramstring$code用户验证码
*@returnbool用户验证码是否正确
*/
publicstaticfunctioncheck($code){
isset($_SESSION)||session_start();
//验证码不能为空
if(empty($code)||empty($_SESSION[self::$seKey])){
returnfalse;
}
//session过期
if(time()-$_SESSION[self::$seKey]['time']>self::$expire){
unset($_SESSION[self::$seKey]);
returnfalse;
}
if($code==$_SESSION[self::$seKey]['code']){
returntrue;
}
returnfalse;
}
}
//useage
/*
YL_Security_Secoder::$useNoise=false;//要更安全的话改成true
YL_Security_Secoder::$useCurve=true;
YL_Security_Secoder::entry();
*/
/*
//验证验证码
if(!YL_Security_Secoder::check(@$_POST['secode'])){
print'errorsecode';
}
*/
这是效果
⑷ PHP代码中怎么样实现文字与图片的混排实现如图所示效果,求代码!
图片样式右浮动<img style="float:right">
⑸ PHP大神求教 因为上传文字和图片是两个类怎么把两个数据组合到一起
你应该说的是两个请求吧,一般上传图片是采用的二进制的传输,而文字的采用的是字符的传输,所以一般不会把两个放到一起。之前做过一个伪ajax的传输方式,是使用的iframe做的。上传和文字的数据提交还是分开的,只是上传图片的是使用iframe,所以页面没有刷新,看起来就像是一起提交了
⑹ PHP后台添加图片信息和文字信息
同时上传啊,比如先inster文字信息进库,query成功之后,再上传图片。
当然也可以先上传图片,再文字入库,文字入库不成功的话,再unlink(删除)掉图片。
上传是没有先后次序的。所有数据一起被发往服务器。
(你的在线编辑器不错,能发我一个吗?[email protected])谢谢。有空我们还能多多交流。QQ就是前面那个数字了。
顺便贴个上传代码给你
if($upload_file !="")
{
$upload_file_name='XXXXXX';
if($upload_file){
$file_size_max = 8388608;// 10M限制(bytes)
$store_dir = "./XXXX/";// 上传位置
$accept_overwrite = 1;//是否允许覆盖
// 检查文件大小
if ($upload_file_size > $file_size_max) {
echo '<div align="center">对不起,你的图片容量大于规定</div>';
exit;
}
// 检查读写文件
if (file_exists($store_dir . $upload_file_name) && !$accept_overwrite) {
Echo '<div align="center">存在相同文件名的图片</div>';
exit;
}
// 复制文件到指定目录
if (!move_uploaded_file($upload_file,$store_dir.$upload_file_name)) {
echo '<div align="center">复制图片失败</div>';
exit;
}
}
$Erroe=$_FILES['upload_file']['error'];
switch($Erroe){
case 0:
Echo '<div align="center">照片上传成功</div>'; break;
case 1:
Echo '<div align="center">上传的图片超过了系统所允许的最大值.</div>'; break;
case 2:
Echo '<div align="center">上传的图片超过了系统所允许的最大值(10M)。</div>'; break;
case 3:
Echo '<div align="center">图片只有部分被上传,请在个人信息修改里添加照片。</div>';break;
case 4:
Echo '<div align="center">图片文件未被上传,请在个人信息修改里添加照片。</div>';break;
}
}
⑺ PHP怎么修改网页文字并提取图片啊
<?php
$text1="第一句";
$text2="第二句";
$text3="第三句";
$url='http://tp.388g.com/aosbegin00006.php?id=736&text1={text1}&text2={text2}&text3={text3}&text4=undefined&text5=undefined&rnd=';
$url=str_replace('{text1}',urlencode($text1),$url);
$url=str_replace('{text2}',urlencode($text2),$url);
$url=str_replace('{text3}',urlencode($text3),$url);
$url=$url.time();
$content=file_get_contents($url);
preg_match('/<outputimg>.(.*?)</outputimg>/is',$content,$matched);
$imgUrl='http://tp.388g.com'.$matched[1];
echo$imgUrl;
exit;
⑻ PHP 文字生成图片
imagecolorallocatealpha用这个函数拾取颜色效果会好很多
⑼ 求代码示例:php将数据库读取出来的文字转成图片显示在页面上
<?php
$Phone=18907975647;#手机号码,具体从数据库怎么读出来,你自己写代码
$im=imagecreate(300,30);#建立一个宽300,高30像素的图片对象
imagecolorallocate($im,255,255,255);#将图片背景填充为白色
$Color=imagecolorallocate($im,0,0,0);#在生成一黑色色颜色,以便写入字符串
imagestring($im,16,0,0,$Phone,$Color);#将字符串写到图片上
header('content-type:image/*');//设置文件头为图片格式
imagepng($im);//输出一个png格式的图片
imagedestroy($im);//销毁图片对象
下面写效果图:
⑽ php 或 js 怎么在图片上添加文字和图片,
需要扩展GD库,例如:
<?php
$im = ImageCreate(70,350);
$white = ImageColorAllocate($im,255,255,255);
$black = ImageColorAllocate($im,0,0,0);
ImageTTFText($im,20,270,28,10,$black,'courbi','The courier TTF font');
header('Content-Type: image/png');
ImagePNG($im);
?>
会将文字竖排排列显示。至于楼主想要的效果,建议楼主先去找一下这方面的资料研究一下吧。很容易的。