php图片函数
Ⅰ php用GD库生成图片用什么函数能让字旋转跟倾斜
图片的旋转和翻转也是Web项目中比较常见的功能,但这是两个不同的概念,图片的旋转是按特定的角度来转动图片,而图片的翻转则是将图片的内容按特定的方向对调。图片翻转需要自己编写函数来实现,而旋转图片则可以直接借助GD库中提供的imagerotate()函数完成。该函数的原型如下所示:
复制代码代码如下:
resource imagerotate(resource src_im , float angle, int bgd_color [,int ignore_transpatrent])
该函数可以将src_im图像用给定的angle角度旋转,bgd_color指定了旋转后没有覆盖到的部分的颜色。旋转的中心是图像的中心,旋转后的图像会按比例缩小以适合目标图像的大小(边缘不会被剪去)。如果ignore_transpatrent被设为非零值,则透明色会被忽略(否则会被保留)。下面以JPEG格式的图片为例,声明一个可以旋转图片的函数rotate(),代码如下所示
Ⅱ php获取图片分辨率 颜色模式函数
$img_info = getimagesize('a.jpg');
print_r($img_info);
索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。
channels 和 bits。channels 对于 RGB 图像其值为 3,对于 CMYK 图像其值为 4。bits 是每种颜色的位数。
Ⅲ php 编写 实现上传图片至服务器的函数
php上传图片客户端和服务器端实现方法分享给大家供大家参考。具体如下:
前台表单代码
<form name="form1" method="post" action="admin_upfile.php" enctype="multipart/form-data">
<input type="file" name="pic">
<input type="submit" name="Submit" value="开始上传" class="button">
</form>
后端php代码
<?php
//这里上传 $upsize判断上传文件的大小
$uppath = "/attached/"; //文件上传路径
//转换根目录的路径
if (strpos($uppath, "/") == 0)
{
$i = 0;
$thpath = $_SERVER["SCRIPT_NAME"];
$thpath = substr($thpath, 1, strlen($thpath));
while (strripos($thpath, "/") !== false)
{
$thpath = substr($thpath, strpos($thpath, "/") + 1, strlen($thpath));
$i = ++$i;
}
$pp = "";
for ($j = 0; $j < $i; ++$j)
{
$pp .= "../";
}
$uppaths = $pp . substr($uppath, 1, strlen($thpath));
}
$filename = date("y-m-d");
if (is_dir($uppaths . $filename) != TRUE)
mkdir($uppaths . $filename, 0777);
$f = $_FILES['pic'];
if ($f["type"] != "image/gif" && $f["type"] != "image/pjpeg" && $f["type"] != "image/jpeg" && $f["type"] != "image/x-png")
{
echo "<script>alert('只能上传图片格式的文件');window.close()</script>";
return false;
}
//获得文件扩展名
$temp_arr = explode(".", $f["name"]);
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
//新文件名
$new_file_name = md5(date("YmdHis")) . '.' . $file_ext;
echo $dest = $uppaths . $filename . "/" . date("ymdhis") . "_" .
$new_file_name; //设置文件名为日期加上文件名避免重复 上传目录
echo $dest1 = $uppath . $filename . "/" . date("ymdhis") . "_" .
$new_file_name; //设置文件名为日期加上文件名避免重复
$r = move_uploaded_file($f['tmp_name'], $dest);
?>
Ⅳ 谁有php批量处理图片、图片生成缩略图、图片添加水印的函数
//批量处理图片、图片生成缩略图、图片添加水印
$dir=opendir(dirname(__FILE__));
while(!!$_file=readdir($dir)){
list($filesname,$kzm)=explode(".",$_file);//获取扩展名
if($kzm=="gif"or$kzm=="jpg"or$kzm=="JPG"or$kzm=="png"){
if(!makethumb("$_file","120","120","100")){
echo'执行成功!';
}else{
echo'执行失败!';
}
}
}
closedir($dir);
/**
*处理缩略图并添加水印函数
*@accesspubliuc
*@param$srcFile-----------图片文件名
*@param$dstFile-----------另存的文件名
*@param$dstW-------------图片保存的宽度
*@param$dstH--------------图片保存的高度
*@param$rate---------------图片保存的品质
*@param$markwords-----水印文字
*@param$markimage-----水印图片
*@param使用方法makethumb("a.jpg","b.jpg","120","120","100");
*/
functionmakethumb($srcFile/*,$dstFile*/,$dstW,$dstH,$rate=100/*,$markwords=null,$markimage=null*/){
$data=GetImageSize($srcFile);
switch($data[2]){
case1:
$im=@ImageCreateFromGIF($srcFile);
break;
case2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
if(!$im)returnFalse;
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$dstX=0;
$dstY=0;
if($srcW*$dstH>$srcH*$dstW){
$fdstH=round($srcH*$dstW/$srcW);
$dstY=floor(($dstH-$fdstH)/2);
$fdstW=$dstW;
}
else
{
$fdstW=round($srcW*$dstH/$srcH);
$dstX=floor(($dstW-$fdstW)/2);
$fdstH=$dstH;
}
$ni=ImageCreateTrueColor($dstW,$dstH);
$dstX=($dstX<0)?0:$dstX;
$dstY=($dstX<0)?0:$dstY;
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX;
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY;
$white=ImageColorAllocate($ni,255,255,255);
$black=ImageColorAllocate($ni,0,0,0);
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white);//填充背景色
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH);
//if($markwords!=null){
//$markwords=iconv("gb2312","UTF-8",$markwords);
////转换文字编码
//ImageTTFText($ni,20,30,450,560,$black,"simhei.ttf",$markwords);//写入文字水印,参数依次为,文字大小|偏转度|横坐标|纵坐标|文字颜色|文字类型|文字内容
//}elseif($markimage!=null){
//$wimage_data=GetImageSize($markimage);
//switch($wimage_data[2]){
//case1:
//$wimage=@ImageCreateFromGIF($markimage);
//break;
//case2:
//$wimage=@ImageCreateFromJPEG($markimage);
//break;
//case3:
//$wimage=@ImageCreateFromPNG($markimage);
//break;
//}
//image($ni,$wimage,500,560,0,0,88,31);//写入图片水印,水印图片大小默认为88*31
//imagedestroy($wimage);
//}
$dstFile=$srcFile.'.gif';
ImageJpeg($ni,$dstFile,$rate);
//ImageJpeg($ni,$srcFile,$rate);
imagedestroy($im);
imagedestroy($ni);
}
Ⅳ PHP图像处理函数有哪些
我在网上找了半天,发现这些都无法实现对它的认识,于是我偶然间找到了相关的资料方面的书;
那就是PHP 手册,表在网上找这些没用的东西了,全是些皮毛介绍,误人子弟;
请点击这里:网页链接下载相关的手册,或者在网上查找PHP相关的中文版的手册;
又全面又仔细,不需要在网上乱查了,根本就是浪费时间,误入歧途.
例子 1. 用 PHP 创建 PNG 图像
<?phpheader("Content-type: image/png");
$string = $_GET['text'];
$im= imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im,
220, 210, 60);
$px= (imagesx($im) - 7.5
* strlen($string)) /
2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
本例应该在一个具有类似:<img
src="button.php?text=text"> 标签的页面中被调用。上述的 button.php 脚本会取得 "text"
字符串将其覆盖在原图上(本例中的
"images/button1.png")并输出作为结果的图像。用此方法可以很方便地修改按钮上的文字从而避免了每次都要新画一个按钮的图像。用此方法就可以动态生成了。
目录
exif_imagetype--判断一个图像的类型
exif_read_data-- 从 JPEG 或 TIFF 文件中读取 EXIF 头信息,这样就可以读取数码相机产生的元数据
exif_thumbnail--取得嵌入在 TIFF 或
JPEG 图像中的缩略图gd_info--取得当前安装的 GD 库的信息
getimagesize--取得图像大小
image_type_to_mime_type-- 取得
getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型image2wbmp--以 WBMP 格式将图像输出到浏览器或文件
imagealphablending--设定图像的混色模式
imageantialias--是否使用 antialias
功能imagearc--画椭圆弧
imagechar--水平地画一个字符
imagecharup--垂直地画一个字符
imagecolorallocate--为一幅图像分配颜色
imagecolorallocatealpha--为一幅图像分配颜色
+ alphaimagecolorat--取得某像素的颜色索引值
imagecolorclosest--取得与指定的颜色最接近的颜色的索引值
imagecolorclosestalpha--取得与指定的颜色
+ alpha 最接近的颜色imagecolorclosesthwb--
取得与给定颜色最接近的色度的黑白色的索引imagecolordeallocate--取消图像颜色的分配
imagecolorexact--取得指定颜色的索引值
imagecolorexactalpha--取得指定的颜色 +
alpha 的索引值imagecolormatch--
使一个图像中调色板版本的颜色与真彩色版本更能匹配imagecolorresolve--
取得指定颜色的索引值或有可能得到的最接近的替代值imagecolorresolvealpha--
取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值imagecolorset--给指定调色板索引设定颜色
imagecolorsforindex--取得某索引的颜色
imagecolorstotal--取得一幅图像的调色板中颜色的数目
imagecolortransparent--将某个颜色定义为透明色
image--拷贝图像的一部分
imagemerge--拷贝并合并图像的一部分
imagemergegray--用灰度拷贝并合并图像的一部分
imageresampled--重采样拷贝部分图像并调整大小
imageresized--拷贝部分图像并调整大小
imagecreate--新建一个基于调色板的图像
imagecreatefromgd2--从 GD2
文件或 URL 新建一图像imagecreatefromgd2part--从给定的
GD2 文件或 URL 中的部分新建一图像imagecreatefromgd--从 GD 文件或
URL 新建一图像imagecreatefromgif--从 GIF
文件或 URL 新建一图像imagecreatefromjpeg--从
JPEG 文件或 URL 新建一图像imagecreatefrompng--从 PNG
文件或 URL 新建一图像imagecreatefromstring--从字符串中的图像流新建一图像
imagecreatefromwbmp--从
WBMP 文件或 URL 新建一图像imagecreatefromxbm--从 XBM
文件或 URL 新建一图像imagecreatefromxpm--从 XPM
文件或 URL 新建一图像imagecreatetruecolor--新建一个真彩色图像
imagedashedline--画一虚线
imagedestroy--销毁一图像
imageellipse--画一个椭圆
imagefill--区域填充
imagefilledarc--画一椭圆弧且填充
imagefilledellipse--画一椭圆并填充
imagefilledpolygon--画一多边形并填充
imagefilledrectangle--画一矩形并填充
imagefilltoborder--区域填充到指定颜色的边界为止
imagefontheight--取得字体高度
imagefontwidth--取得字体宽度
imageftbbox--取得使用了 FreeType 2
字体的文本的范围imagefttext--使用 FreeType 2
字体将文本写入图像imagegammacorrect--对 GD 图像应用
gamma 修正imagegd2--输出 GD2 图像
imagegd--将 GD 图像输出到浏览器或文件
imagegif--以 GIF 格式将图像输出到浏览器或文件
imageinterlace--激活或禁止隔行扫描
imageistruecolor--检查图像是否为真彩色图像
imagejpeg--以 JPEG 格式将图像输出到浏览器或文件
imagelayereffect-- Set the
alpha blending flag to use the bundled libgd layering effectsimageline--画一条直线
imageloadfont--载入一新字体
imagepalette--将调色板从一幅图像拷贝到另一幅
imagepng--以 PNG 格式将图像输出到浏览器或文件
imagepolygon--画一个多边形
imagepsbbox--取得使用 PostScript Type1
字体的文本的范围imagepsfont--
拷贝一个已加载的字体以备更改imagepsencodefont--改变字体中的字符编码矢量
imagepsextendfont--扩充或压缩字体
imagepsfreefont--释放一个
PostScript Type 1 字体所占用的内存imagepsloadfont--从文件中加载一个
PostScript Type 1 字体imagepsslantfont--倾斜某字体
imagepstext--用 PostScript Type1
字体把文本字符串画在图像上imagerectangle--画一个矩形
imagerotate--用给定角度旋转图像
imagesavealpha-- 设置标记以在保存 PNG
图像时保存完整的 alpha 通道信息(与单一透明色相反)imagesetbrush--设定画线用的画笔图像
imagesetpixel--画一个单一像素
imagesetstyle--设定画线的风格
imagesetthickness--设定画线的宽度
imagesettile--设定用于填充的贴图
imagestring--水平地画一行字符串
imagestringup--垂直地画一行字符串
imagesx--取得图像宽度
imagesy--取得图像高度
imagetruecolortopalette--将真彩色图像转换为调色板图像
imagettfbbox--取得使用 TrueType
字体的文本的范围imagettftext--用 TrueType
字体向图像写入文本imagetypes--返回当前 PHP 版本所支持的图像类型
imagewbmp--以 WBMP 格式将图像输出到浏览器或文件
iptcembed--将二进制 IPTC 数据嵌入到一幅 JPEG
图像中iptcparse-- 将二进制 IPTC http://www.iptc.org/ 块解析为单个标记
jpeg2wbmp--将 JPEG 图像文件转换为 WBMP 图像文件
png2wbmp--将 PNG 图像文件转换为 WBMP 图像文件
read_exif_data--exif_read_data() 的别名
Ⅵ 求php图片缩放处理函数
<?php
/**
*图片缩放
*@paramstring$url
*@paramint$maxWidth
*@paramint$maxHeight
*@returnstring
*/
functionthumb($url,$maxWidth,$maxHeight,&$info){
$info=$imgInfo=getimagesize($url);
$width=$imgInfo[0];//获取图片宽度
$height=$imgInfo[1];//获取图片高度
$r=min($maxHeight/$height,$maxWidth/$width);
if($r>=1){//不用缩放
$maxHeight=$height;
$maxWidth=$width;
}elseif($r<1){//缩放
$maxHeight=$height*$r;
$maxWidth=$width*$r;
}
$temp_img=imagecreatetruecolor($maxWidth,$maxHeight);//创建画布
$fun=str_replace('/','createfrom',$imgInfo['mime']);
$im=$fun($url);
imageresized($temp_img,$im,0,0,0,0,$maxWidth,$maxHeight,$width,$height);
ob_start();
$fun=str_replace('/','',$imgInfo['mime']);
$fun($temp_img);
$imgstr=ob_get_contents();
ob_end_clean();
imagedestroy($im);
return$imgstr;
}
$imgUrl=$_GET['url'];
$info=array();
$string=thumb($imgUrl,500,500,$info);
$mimeArray=explode("/",$info['mime']);
header("Content-Type:image/{$mimeArray[1]}");
echo$string;
以上代码存为thumb.php,调用效果: