php数据生成图片格式 php格式的图片

求代码示例: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怎么把图片数据保存为jpg图片到服务器目录

第一步:通过$_FILES获取文件信息。

第二步:指定新文件名称以及路径,并赋值给一个变量。

第三步:通过move_uploaded_file上传文件。

第四步:上传成功后,将数值存入数据库服务器目录即可。

代码如下

1.conn.php

$host="localhost"; //数据库服务器名称 

$user="root"; //用户名 

$pwd="1721"; //密码 

$conn=mysql_connect($host,$user,$pwd); 

mysql_query("SET 

character_set_connection=gb2312, 

character_set_results=gb2312, 

character_set_client=binary",$conn); 

if ($conn==FALSE) 

echo "center服务器连接失败!br请刷新后重试。/center"; 

return true; 

$databasename="database";//数据库名称 

do 

$con=mysql_select_db($databasename,$conn); 

}while(!$con); 

if ($con==FALSE) 

echo "center打开数据库失败!br请刷新后重试。/center"; 

return true; 

?

2.upload.php

?php 

if ($_GET['action'] == "save"){ 

include_once('conn.php'); 

include_once('uploadclass.php'); 

$title=$_POST['title']; 

$pic=$uploadfile; 

if($title == "") 

echo"Scriptwindow.alert('对不起!你输入的信息不完整!');history.back()/Script"; 

$sql="insert into upload(title,pic) values('$title','$pic')"; 

$result=mysql_query($sql,$conn); 

//echo"Scriptwindow.alert('信息添加成功');location.href='upload.php'/Script"; 

html 

head 

title文件上传实例/title 

/head 

body 

form method="post" action="?action=save" enctype="multipart/form-data" 

table border=0 cellspacing=0 cellpadding=0 align=center width="100%" 

tr 

td width=55 height=20 align="center" /TD 

td height="16" 

table width="48%" height="93" border="0" cellpadding="0" cellspacing="0" 

tr 

td标题:/td 

tdinput name="title" type="text" id="title"/td 

/tr 

tr 

td文件: /td 

tdlabel 

input name="file" type="file" value="浏览"  

input type="hidden" name="MAX_FILE_SIZE" value="2000000" 

/label/td 

/tr 

tr 

td /td 

tdinput type="submit" value="上 传" name="upload"/td 

/tr 

/table/td 

/tr 

/table 

/form 

/body 

/html

3.uploadclass.php

?php 

$uploaddir = "upfiles/";//设置文件保存目录 注意包含/ 

$type=array("jpg","gif","bmp","jpeg","png");//设置允许上传文件的类型 

$patch="upload/";//程序所在路径 

//获取文件后缀名函数 

function fileext($filename) 

return substr(strrchr($filename, '.'), 1); 

//生成随机文件名函数 

function random($length) 

$hash = 'CR-'; 

$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; 

$max = strlen($chars) - 1; 

mt_srand((double)microtime() * 1000000); 

for($i = 0; $i  $length; $i++) 

$hash .= $chars[mt_rand(0, $max)]; 

return $hash; 

$a=strtolower(fileext($_FILES['file']['name'])); 

//判断文件类型 

if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type)) 

$text=implode(",",$type); 

echo "您只能上传以下类型文件: ",$text,"br"; 

//生成目标文件的文件名 

else{ 

$filename=explode(".",$_FILES['file']['name']); 

do 

$filename[0]=random(10); //设置随机数长度 

$name=implode(".",$filename); 

//$name1=$name.".Mcncc"; 

$uploadfile=$uploaddir.$name; 

while(file_exists($uploadfile)); 

if (move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile)) 

if(is_uploaded_file($_FILES['file']['tmp_name'])) 

echo "上传失败!"; 

else 

{//输出图片预览 

echo "center您的文件已经上传完毕 上传图片预览: /centerbrcenterimg src='$uploadfile'/center"; 

echo "brcentera href='upload.htm'继续上传/a/center"; 

?

PHP怎么转换图片格式?

用下面代码(PHP必须支持GD库)

$input=上传的BMP文件名

$output=要存的jpeg文件名

$image=imagecreatefromwbmp($input);

imagejpeg($image,$output);

imagedestroy($image);

unlink($input);

用GD库还可以加水印、改大小等,网上都有,一搜就行。我是按照PHP手册

你可以去后盾人平台看一下,里面的东西不错

Php怎么把数据库中图片的路径转化为图片呢?

先用php把数据库中的图片路径读取出来,然后把这个路径嵌入到img元素的src中,就相当于把图片的路径转化为图片了。

当前标题:php数据生成图片格式 php格式的图片
浏览路径:https://www.cdcxhl.com/article48/ddscihp.html

成都网站建设公司_创新互联,为您提供小程序开发虚拟主机面包屑导航自适应网站App设计App开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计