php 图形处理函数imagetype

 更新时间:2016年11月25日 17:11  点击:2027

php教程 图形处理函数imagetypes() imagecreatetruecolor() imagecreate()
//判断当前的gd库是否支持png

if(imagetypes() & img_png)
{
  echo "png support is enabled";
}
else
{
  echo "png support is disabled";
}
/*
int imagetypes ( void )


本函数以比特字段方式返回与当前 php 版本关联的 gd 库所支持的图像格式。将返回以下结果,img_gif | img_jpg | img_png | img_wbmp| img_xpm。 例如要检查是否支持 png

*/

//创建图像
$img=imagecreatetruecolor(300,200);
//取得图像宽度
echo imagesx($img);


/*
看个实例
*/

//建立一幅 100x30 的图像
$im=imagecreate(100,30);
//白色背景和蓝色文本
$bg=imagecolorallocate($im,255,255,255);
$textcolor=imagecolorallocate($im,0,0,255);
//把字符串写在图像左上角
imagestring($im,5,0,0,"hello world!",$textcolor);
//输出图像
header("content-type: image/png");
imagepng($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);

取得 php教程 的配置选项值。

语法: string get_cfg_var(string varname);

返回值: 字符串

函数种类: php 系统功能
内容说明

若正确取得目前 php 配置选项 varname,则返回变量值。失败则返回 false。

 

*/
echo "php设置的最大执行时间为:n";
print_r(get_cfg_var("max_execution_time"));       //获得配置项的值
echo "<br>n";
echo "php设置的每个脚本的可使用内存总量为:n";
print_r(get_cfg_var("memory_limit"));         //获得配置项的值
echo "<br>n";
echo "php设置的接受post的最大大小为:n";
print_r(get_cfg_var("post_max_size"));        //获得配置项的值
echo "<br>n";
echo "php设置smtp服务器名为:n";
print_r(get_cfg_var("smtp"));          //获得配置项的值
echo "<br>n";
echo "php设置的上传文件的最大大小为:n";
print_r(get_cfg_var("upload_max_filesize"));       //获得配置项的值
echo "<br>n";

<?php教程


//连接数据库教程
$link = mysql教程_connect('localhost','root','密码') or die(mysql_error());
mysql_select_db('sortclass',$link);
mysql_query("set names 'gbk'");
//无限分类类库
class sortclass{

var $data = array();
var $child = array(-1=>array());
var $layer = array(-1=>-1);
var $parent = array();
var $link;
var $table;
function sortclass($link, $table){
$this->setnode(0, -1, '顶极节点');
$this->link = $link;
$this->table = $table;
$node = array();
$results = mysql_query('select * from '.$this->table.'',$this->link);
while($node = mysql_fetch_assoc($results)){
$this->setnode($node['cid'],$node['pid'],$node['cname']);
}
}
function setnode ($id, $parent, $value){
$parent = $parent?$parent:0;
$this->data[$id] = $value;
$this->child[$id] = array();
$this->child[$parent][] = $id;
$this->parent[$id] = $parent;
$this->layer[$id] = !isset($this->layer[$parent])? 0 : $this->layer[$parent] + 1;
}
function getlist (&$tree, $root= 0){
foreach ($this->child[$root] as $key=>$id){
$tree[] = $id;
if ($this->child[$id]) $this->getlist($tree, $id);
}
}
function getvalue ($id){return $this->data[$id];}
function getlayer ($id, $space = false){
return $space?str_repeat($space, $this->layer[$id]):$this->layer[$id];
}
function getparent ($id){return $this->parent[$id];}
function getparents ($id){
while ($this->parent[$id] != -1){
$id = $parent[$this->layer[$id]] = $this->parent[$id];
}
ksort($parent);
reset($parent);
return $parent;
}
function getchild ($id){return $this->child[$id];}
function getchilds ($id = 0){
$child = array($id);
$this->getlist($child, $id);
return $child;
}
function addnode($name,$pid){
mysql_query("insert into $this->table (`pid`,`cname`) values ('$pid','$name')",$this->link);
}
function modnode($cid, $newname){
mysql_query("update $this->table set `cname`='$newname' where `cid` = $cid",$this->link);
}
function delnode($cid){
$allchilds = $this->getchilds($cid);
$sql ='';
if(empty($allchilds)){
$sql = "delete from $this->table where `cid` = $cid";
}else{
$sql = 'delete from '.$this->table.' where `cid` in ('.implode(',',$allchilds).','.$cid.')';
}
mysql_query($sql,$this->link);
}
function movenode($cid, $topid){
mysql_query("update $this->table set `pid`=$topid where `cid` = $cid", $this->link);
}
}
//函数
function back(){
echo '<script language="网页特效">window.location.href="class.php?"+new date().gettime();</script>';
exit;
}
//生成select
function makeselect($array,$formname){
global $tree;
$select = '<select name="'.$formname.'">';
foreach ($array as $id){
$select.='<option value="'.$id.'">'.$tree->getlayer($id, '|-').$tree->getvalue($id)."</option>";
}
return $select.'</select>';
}
$tree = new sortclass($link,'`class`');
$op = !empty($_post['op']) ? $_post['op'] : $_get['op'];
if(!empty($op)){

if($op=='add'){
$tree->addnode($_post['cname'],$_post['pid']);
back();
}

if($op=='mod'){
$tree->modnode($_post['cid'],$_post['cname']);
back();
}

if($op=='del'){
$tree->delnode($_get['cid']);
back();
}

if($op=='move'){
$tree->movenode($_post['who'],$_post['to']);
back();
}
}
$category = $tree->getchilds();
?>
<style type="text/css教程">
body{font-size:12px;}
ul{list-style:none;}
a{cursor:pointer;}
input{ margin-top:8px;}
</style>
<script language="javascript">
function $(e){return document.getelementbyid(e);}
function mod(cid){
$('cid').value=cid;
$('op').value='mod';
$('name').style.border='1px solid red';
}
</script>
<h3>添加分类</h3>
<form action="class.php" method="post">
名称:<input type="text" id="name" name="cname" /> 添加到:<?=makeselect($category,'pid')?><br />
<input type="hidden" id="op" name="op" value="add" />
<input type="hidden" id="cid" name="cid" />
<input type="submit" value="添加分类" />
</form>
<h3>移动分类</h3>
<form action="class.php" method="post">
<?=makeselect($category,'who')?>移动到:<?=makeselect($category,'to')?>
<input type="hidden" id="op" name="op" value="move" />
<input type="submit" value="移动" />
</form>
<ul>
<?php
foreach ($category as $id){
echo '<li>'.$tree->getlayer($id, '|- ').$tree->getvalue($id).' <a href="class.php?op=del&cid='.$id.'">del</a> <a onclick="mod('.$id.')">edit</a> </li>';
}
?>
</ul>
完整的新闻无限级分类代码,可添加,删除,移动,修改


顶极节点 del   edit
|- 1级分类del   edit
|- 1级分类 del   edit
|- 1级分类 del   edit
|- |- 2级分类 del   edit
|- |- |- 3级分类 del  edit
|- |- |-|- 4级分类 del  edit
|- 1级分类 del   edit


<!--

create database `sortclass`default charset utf8;
create table if not exists `class` (
`cid` mediumint(8) unsigned not null auto_increment,
`pid` mediumint(8) unsigned not null,
`cname` varchar(50) not null,
primary key (`cid`),
key `pid` (`pid`)
) engine=myisam default charset=utf8;

--->

get_headers是获取http头信息,get_meta_tags是获取网页的description,abstract,keywords等信息


*/
$url='http://www.111cn.net';          //定义url
print_r(get_headers($url));         //无格式获取
print_r(get_headers($url,1));         //带上格式获取


/*

array
(
    [0] => http/1.1 200 ok
    [1] => connection: close
    [2] => date: sat, 11 dec 2010 05:43:46 gmt
    [3] => content-length: 69617
    [4] => content-type: text/html
    [5] => content-location: http://www.111cn.net/

    [6] => last-modified: sat, 11 dec 2010 05:19:51 gmt
    [7] => accept-ranges: bytes
    [8] => etag: "e8be4b9f398cb1:6c66"
    [9] => server: microsoft-iis/6.0
    [10] => x-powered-by: asp教程.net
)
array
(
    [0] => http/1.1 200 ok
    [connection] => close
    [date] => sat, 11 dec 2010 05:43:47 gmt
    [content-length] => 69617
    [content-type] => text/html
    [content-location] => http://www.111cn.net/index.html
    [last-modified] => sat, 11 dec 2010 05:19:51 gmt
    [accept-ranges] => bytes
    [etag] => "e8be4b9f398cb1:6c66"
    [server] => microsoft-iis/6.0
    [x-powered-by] => asp.net教程
)

get_meta_tags($url);
获取指定网页的description,abstract,keywords等信息
*/

$tags=get_meta_tags('http://www.111cn.net/');      //提取meta标签
print_r($tags)            //输出数组全部内容

/*

array
(
    [description] => 网页制作教程网提供专业网页设计教程与网页制作教程包括有photoshop教程,flash,html,css教程,dreamweaver,fireworks,asp,php教程,jsp教程,asp.net,网站建设,网站开发,网页特效,平面设计,个人网站,网页素材
    [abstract] => 提供最新的网页制作教程、网页设计教程、网页特效,为个人网站提供网页素材模板和网页视频学习。
    [keywords] => 网页设计教程,网页制作教程,网页学习,photoshop,flash,html,css,dreamweaver,fireworks,asp,php,jsp,asp.net,网页特效,平面设计,网页素材
)

注意:使用该函数需要把 php.ini里面的allow_url_fopen = on,才能使用

COOKIE 是在网页内容发送之前。先发送出去的信息。也就是说。在这之前不能有任何的 HTML 代码和 echo 等,即使是一个空格也是不允许的。。

在php教程中,要用 setcookie 函数来注册 cookie 变量,你上面的代码没有注册 cookie 变量。怎么可能送得过去呢。正确的写法如下:

*/
$status=0;                //定义状态
if(isset($_cookie['mytstcky'])&&($_cookie['mytstcky']=="chocchip")) $status=1; //如果已经设置变量
if(!isset($_get['cchk']))             //如果没有设置变量
{
  setcookie("mytstcky","chocchip");          //发送cookie信息
  header("location:$php_self?cchk=1");         //发送标头
  exit;                //结束php代码
}
?>
<html>
<head><title>cookie check</title></head>
<body bgcolor="#ffffff" text="#000000">
cookie check status:
<?php
printf('<font color="#%s">%s</font><br>;',$status ? "00ff00" : "ff0000",$status ? "passed!" : "failed!");               //根据条件输出不同内容
?>
</body>
</html>

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • Windows批量搜索并复制/剪切文件的批处理程序实例

    这篇文章主要介绍了Windows批量搜索并复制/剪切文件的批处理程序实例,需要的朋友可以参考下...2020-06-30
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • BAT批处理判断服务是否正常运行的方法(批处理命令综合应用)

    批处理就是对某对象进行批量的处理,通常被认为是一种简化的脚本语言,它应用于DOS和Windows系统中。这篇文章主要介绍了BAT批处理判断服务是否正常运行(批处理命令综合应用),需要的朋友可以参考下...2020-06-30
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • PS怎么排除重叠图形

    PS排除重叠形状是什么意思?很多朋友都不是很清楚,其实方法很简单的,下面小编就为大家介绍介绍一下,不会的朋友可以参考本文,来看看吧。 步骤:1、在PS中,选择“矩形工具...2016-12-31
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • PHP函数strip_tags的一个bug浅析

    PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数...2014-05-31
  • PHP file_get_contents设置超时处理方法

    file_get_contents的超时处理话说,从PHP5开始,file_get_content已经支持context了(手册上写着:5.0.0 Added the context support. ),也就是说,从5.0开始,file_get_contents其实也可以POST数据。今天说的这篇是讲超时的,确实在...2013-10-04
  • SQL Server中row_number函数的常见用法示例详解

    这篇文章主要给大家介绍了关于SQL Server中row_number函数的常见用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
  • C#多线程中的异常处理操作示例

    这篇文章主要介绍了C#多线程中的异常处理操作,涉及C#多线程及异常的捕获、处理等相关操作技巧,需要的朋友可以参考下...2020-06-25