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,調用效果: