導航:首頁 > 編程語言 > phphtmltoimage

phphtmltoimage

發布時間:2022-11-29 23:22:23

㈠ 怎樣用php實現上傳圖片到資料庫

php實現上傳圖片保存到資料庫的方法。具體分析如下:

php 上傳圖片,一般都使用move_uploaded_file方法保存在伺服器上。但如果一個網站有多台伺服器,就需要把圖片發布到所有的伺服器上才能正常使用(使用圖片伺服器的除外)
如果把圖片數據保存到資料庫中,多台伺服器間可以實現文件共享,節省空間。

首先圖片文件是二進制數據,所以需要把二進制數據保存在mysql資料庫。
mysql資料庫提供了BLOB類型用於存儲大量數據,BLOB是一個二進制對象,能容納不同大小的數據。

BLOB類型有以下四種,除存儲的最大信息量不同外,其他都是一樣的。可根據需要使用不同的類型。

TinyBlob 最大 255B
Blob 最大 65K
MediumBlob 最大 16M
LongBlob 最大 4G

數據表photo,用於保存圖片數據,結構如下:

CREATETABLE`photo`(
`id`int(10)unsignedNOTNULLauto_increment,
`type`varchar(100)NOTNULL,
`binarydata`mediumblobNOTNULL,
PRIMARYKEY(`id`)
)ENGINE=MyISAMDEFAULTCHARSET=latin1AUTO_INCREMENT=1;

upload_image_todb.php代碼如下:

<?php
//連接資料庫
$conn=@mysql_connect("localhost","root","")ordie(mysql_error());
@mysql_select_db('demo',$conn)ordie(mysql_error());//判斷action
$action=isset($_REQUEST['action'])?$_REQUEST['action']:'';
//上傳圖片
if($action=='add'){
$image=mysql_escape_string(file_get_contents($_FILES['photo']['tmp_name']));
$type=$_FILES['photo']['type'];
$sqlstr="insertintophoto(type,binarydata)values('".$type."','".$image."')";
@mysql_query($sqlstr)ordie(mysql_error());
header('location:upload_image_todb.php');
exit();
//顯示圖片
}elseif($action=='show'){
$id=isset($_GET['id'])?intval($_GET['id']):0;
$sqlstr="select*fromphotowhereid=$id";
$query=mysql_query($sqlstr)ordie(mysql_error());
$thread=mysql_fetch_assoc($query);
if($thread){
header('content-type:'.$thread['type']);
echo$thread['binarydata'];
exit();
}
}else{
//顯示圖片列表及上傳表單
?>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="content-type"content="text/html;charset=utf-8">
<title>uploadimagetodbdemo</title>
</head>

<body>
<formname="form1"method="post"action="upload_image_todb.php"enctype="multipart/form-data">
<p>圖片:<inputtype="file"name="photo"></p>
<p><inputtype="hidden"name="action"value="add"><inputtype="submit"name="b1"value="提交"></p>
</form>

<?php
$sqlstr="select*fromphotoorderbyiddesc";
$query=mysql_query($sqlstr)ordie(mysql_error());
$result=array();
while($thread=mysql_fetch_assoc($query)){
$result[]=$thread;
}
foreach($resultas$val){
echo'<p><img
src="upload_image_todb.php?action=show&id='.$val['id'].'&t='.time().'"
width="150"></p>';
}
?>
</body>
</html>
<?php
}
?>

程序運行截圖和資料庫截圖:

㈡ 用html或php怎樣簡單的實現單擊下載圖片

下面是來自ci的下載輔助函數,基本原理是生成一個能下載數據的http header,然後把文件數據發送過去就行啦。應該是可以直接用的,如果還有什麼問題,我再看看啊
$data = file_get_contents("/path/to/photo.jpg"); // 讀文件內容
$name = 'myphoto.jpg';

force_download($name, $data);

function force_download($filename = '', $data = '')
{
if ($filename == '' OR $data == '')
{
return FALSE;
}

// Try to determine if the filename includes a file extension.
// We need it in order to set the MIME type
if (FALSE === strpos($filename, '.'))
{
return FALSE;
}

// Grab the file extension
$x = explode('.', $filename);
$extension = end($x);

$mimes = array( 'bmp' => array('image/bmp','application/octet-stream'),
'gif' => array('image/gif','application/octet-stream'),
'jpeg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpe' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'png' => array('image/png', 'image/x-png', 'application/octet-stream')
);

// Set a default mime if we can't find it
if ( ! isset($mimes[$extension]))
{
$mime = 'application/octet-stream';
}
else
{
$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
}

// Generate the server headers
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: ".strlen($data));
}
else
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".strlen($data));
}

exit($data);
}

㈢ php+html能夠實現視頻的在線 播放嗎

1、通過網頁(HTML5)調用攝像頭,通過websocket傳輸給PHP後端(workerman), 再由後端廣播給所有在線播放網頁,觀看者可以通過這個播放頁面實時觀看攝像頭拍攝的內容。
2、
可以通過html版本的flash播放器
<p id="player3">
<a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
var s1 = new SWFObject("flvplayer.swf","single","300","170","7");
s1.addParam("allowfullscreen","true");
s1.addVariable("file","videos /ld.Flv");//這邊是視頻在本地的路徑
s1.addVariable("image"," videos/ld.jpg");//這邊是你的視頻的截圖
s1.addVariable("width","300");
s1.addVariable("height","170");
s1.write("player3");
</script>
通常是用flv 播放器。
3、你可以直接把視頻的這段html代碼弄過來。
<embed src="http://player.youku.com/player.php/sid/XNDc4NDU1NjAw/v.swf" allowFullScreen="true" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>
,搞個層,點擊時候,彈出這個視頻。

㈣ php圖片上傳前預覽怎麼實現!!

1.先創建一個file表單域,我們需要用它來瀏覽本地文件。
<form name="form1" id="form1" method="post" action="upload.php">
<input type="file" name="file1" id="file1" />
</form>
2.試下效果:
判斷文件類型:
當用戶選擇了一個圖片文件時,希望他能馬上看到這張圖片的縮略圖,以便他能確認沒有把自己的光屁股照片當作頭像傳到伺服器上^_^。
在預覽之前還得先判斷一下用戶選擇的是不是一個圖像文件,如果他想用一個.rar文件做頭像的話我們也需要禮貌地提醒一下。
<form name="form2" id="form2" method="post" action="upload.php">
<input type="file" name="file2" id="file2"
onchange="preview()" />
</form>
Javascript函數實現,注意使用DOM方法getElementById來訪問對象。不要再使用form
和input的name屬性來訪問對象了,只有IE才這么干。<script type="text/javascript">
function preview2(){
var x = document.getElementById("file2");
if(!x || !x.value) return;
if(x.value.indexOf(".jpg")<0
&& x.value.indexOf(".jpeg")<0
&& x.value.indexOf(".gif")<0){
alert("您選擇的似乎不是圖像文件。");
}else{
alert("通過");
}
}
</script>
3.試下效果:

這里有一個問題,如果用戶選擇了名為「fake.jpg.txt」的文件,這段腳本仍舊會認為這是一個合法的圖像文件。一個可行的解決方案是先 把文件名轉換成小寫,再取文件路徑的最後4到5位,判斷一下文件的擴展名是否確為支持的圖像文件擴展名。不過這種方案略顯笨拙,也沒有什麼美感可言, 我們換一種方案:用「正則表達式」來判斷文件擴展名。
<script type="text/javascript">
function preview3(){
var x = document.getElementById("file3");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
alert("通過");
}else{
alert("您選擇的似乎不是圖像文件。");
}
}
</script>
4.看看效果(可以自己創建一個「fake.jpg.txt」文件試試):

回到這段腳本上來,即使你還看不懂正則表達式那兩行,但整段腳本的美感還是很明顯的:簡潔、直接、語義流暢,這與Web標准關於XHTML的要求是一致的,與Web設計師或開發者天生的「完美」主義也是一致的。
jjww一大段之後,轉入重點——預覽圖片
預覽功能的基本設計思路是很清晰的:創建一個img元素,再把文件域的value值賦值給img
元素的src屬性。<form name="form4" id="form4" method="post" action="#">
<input type="file" name="file4" id="file4"
onchange="preview4()" />
<img id="pic4" src="http://blog.163.com/lgh_2002/blog/" alt="圖片在此顯示" width="120"/>
</form>
<script type="text/javascript">
function preview4(){
var x = document.getElementById("file4");
var y = document.getElementById("pic4");
if(!x || !x.value || !y) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
y.src = "file://localhost/" + x.value;
}else{
alert("您選擇的似乎不是圖像文件。");
}
}
</script>
5.試下效果:

如果用的是Firefox(或Opera),可能會發現什麼也沒有發生。是的,很不幸Firefox的安全策略不允許顯示一個用戶的本地 圖像文件。不知道為什麼要這么做,個人覺得圖像文件並不會造成嚴重的安全性問題。即使是不久前比較熱門的那個會引起Windows崩潰的jpeg文 件,要顯示它的前提條件是用戶自己選擇了這個文件或者你知道這個文件在用戶硬碟上的准確路徑。所以我想這種策略很可能來自於一個「懶惰」的開發人員,並 不想多寫一些程序來區分這個本地文件是一個圖像文件還是一個惡意文件,Firefox對安全性的要求讓他們有些過於敏感了。
讓Firefox顯示本地文件的唯一辦法就是修改它的默認安全策略:
在Firefox的地址欄中輸入「about:config」
繼續輸入「security.checkloari」
雙擊下面列出來的一行文字,把它的值由true改為false
然後你可以再試試上面預覽,everything works well!可惜的是並不能要求所有的用戶都去修改這個值(更不用說修改的過程還挺麻煩),所以毫無意義。我們能做的也許就是接受Firefox不能預覽本地圖片這種「可笑」的局面。
用DOM來創建對象
在上面的XHTML代碼中,為了預覽圖片,事先加入了一個沒有設置src的img對象。除去不美觀、代碼冗餘之外,如果用戶瀏覽器不支持 Javascript,不僅無法使用這個功能,還要接受頁面上一個永遠不會顯示出來的破圖。要解決這個問題,就需要在「運行時」再生成這個img對 象,途徑還是DOM。
<form name="form5" id="form5" method="post" action="#">
<input type="file" name="file5" id="file5"
onchange="preview5()"/>
</form>
<script type="text/javascript">
function preview5(){
var x = document.getElementById("file5");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
var y = document.getElementById("img5");
if(y){
y.src = 'file://localhost/' + x.value;
}else{
var img=document.createElement('img');
img.setAttribute('src','file://localhost/'+x.value);
img.setAttribute('width','120');
img.setAttribute('height','90');
img.setAttribute('id','img5');
document.getElementById('form5').appendChild(img);
}
}else{
alert("您選擇的似乎不是圖像文件。");
}
}
</script>
6.試下效果:

這樣就相對比較完美了。DOM和正則表達式一樣,都是「包你不悔」的實 用技術,如果你希望更多了解、深入學習、或者順利實踐Web標准,DOM是不可或缺的。從本人最近的體會來說,Javascript+DOM+CSS蘊 藏著強大的能量,就看怎麼釋放它了。

7.最後帖上JQUERY的上傳預覽代碼:

de><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://blog.163.com/lgh_2002/blog/jquery.js"></script>
<script language="javascript">
$(function(){
var ei = $("#large");
ei.hide();
$("#img1").mousemove(function(e){
ei.css({top:e.pageY,left:e.pageX}).html('<img style="border:1px solid gray;" src="http://blog.163.com/lgh_2002/blog/' + this.src + '" />').show();
}).mouseout( function(){
ei.hide("slow");
})
$("#f1").change(function(){
$("#img1").attr("src","file:///"+$("#f1").val());
})
});
</script>
<style type="text/css">
#large{position:absolute;display:none;z-index:999;}
</style>
</head>
<body>
<form name="form1" id="form1">
<div id="demo">
<input id="f1" name="f1" type="file" />
<img id="img1" width="60" height="60">
</div>
<div id="large"></div>
</form>
</body>
</html>de>

㈤ PHP圖片生成

給你一個php 圖像處理類,完全能實現你的功能,你自己研究一下吧

<?php
class image
{
var $w_pct = 50; //透明度
var $w_quality = 80; //質量
var $w_minwidth = 300; //最小寬
var $w_minheight = 300; //最小高
var $thumb_enable; //是否生成縮略圖
var $watermark_enable; //是否生水印
var $interlace = 0; //圖像是否為隔行掃描的
var $fontfile; //字體文件
var $w_img ; //默認水印圖

function __construct()
{
global $SITE_CONFING;
$this->thumb_enable = $SITE_CONFING['thumb_enable'];
$this->watermark_enable = $SITE_CONFING['watermark_enable'];
$this->set($SITE_CONFING['watermark_minwidth'], $SITE_CONFING['watermark_minheight'], $SITE_CONFING['watermark_quality'], $SITE_CONFING['watermark_pct'], $SITE_CONFING['watermark_fontfile'],$SITE_CONFING['watermark_img']);
}

function image()
{
$this->__construct();
}

function set($w_minwidth = 300, $w_minheight = 300, $w_quality = 80, $w_pct = 100,$fontfile,$w_img)
{
$this->w_minwidth = $w_minwidth;
$this->w_minheight = $w_minheight;
$this->w_quality = $w_quality;
$this->w_pct = $w_pct;
$this->fontfile = $fontfile;
$this->w_img = $w_img;
}

function info($img)
{
$imageinfo = getimagesize($img); //返回圖像信息數組 0=>寬的像素 1=>高的像素 2=>是圖像類型的標記 3 =>是文本字元串,內容為「height="yyy" width="xxx"」,
if($imageinfo === false) return false;
$imagetype = strtolower(substr(image_type_to_extension($imageinfo[2]),1)); //獲取圖像文件類型 $imageinfo[2]是圖像類型的標記
$imagesize = filesize($img); //圖像大小
$info = array(
'width'=>$imageinfo[0],
'height'=>$imageinfo[1],
'type'=>$imagetype,
'size'=>$imagesize,
'mime'=>$imageinfo['mime']
);
return $info;
}

function thumb($image, $filename = '', $maxwidth = 200, $maxheight = 50, $suffix='_thumb', $autocut = 0)
{
if(!$this->thumb_enable || !$this->check($image)) return false;
$info = $this->info($image); //獲取圖片信息
if($info === false) return false;
$srcwidth = $info['width']; //源圖寬
$srcheight = $info['height']; //源圖高
$pathinfo = pathinfo($image);
$type = $pathinfo['extension']; //取得擴展名
if(!$type) $type = $info['type']; //如果沒有取到,用$info['type']
$type = strtolower($type);
unset($info);
$scale = min($maxwidth/$srcwidth, $maxheight/$srcheight); //獲取縮略比例
//獲取按照源圖的比列
$createwidth = $width = (int)($srcwidth*$scale); //取得縮略寬
$createheight = $height = (int)($srcheight*$scale); //取得縮略高
$psrc_x = $psrc_y = 0;
if($autocut) //按照縮略圖的比例來獲取
{
if($maxwidth/$maxheight<$srcwidth/$srcheight && $maxheight>=$height) //如果縮略圖按比列比源圖窄的話
{
$width = $maxheight/$height*$width; //寬按照相應比例做處理
$height = $maxheight; //高不變
}
elseif($maxwidth/$maxheight>$srcwidth/$srcheight && $maxwidth>=$width)//如果縮略圖按比列比源圖寬的話
{
$height = $maxwidth/$width*$height;
$width = $maxwidth;
}
$createwidth = $maxwidth;
$createheight = $maxheight;
}
$createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type); //找到不同的圖像處理函數
$srcimg = $createfun($image); //新建圖像
if($type != 'gif' && function_exists('imagecreatetruecolor'))
$thumbimg = imagecreatetruecolor($createwidth, $createheight); //新建一個真彩色圖像
else
$thumbimg = imagecreate($width, $height); //新建一個基於調色板的圖像

if(function_exists('imageresampled')) //重采樣拷貝部分圖像並調整大小,真彩
//imageresampled(新圖,源圖,新圖左上角x距離,新圖左上角y距離,源圖左上角x距離,源圖左上角y距離,新圖寬,新圖高,源圖寬,源圖高)
imageresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight);
else //拷貝部分圖像並調整大小,調色板
imageresized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight);
if($type=='gif' || $type=='png')
{
//imagecolorallocate 為一幅圖像分配顏色
$background_color = imagecolorallocate($thumbimg, 0, 255, 0); // 給基於調色板的圖像填充背景色, 指派一個綠色
// imagecolortransparent 將某個顏色定義為透明色
imagecolortransparent($thumbimg, $background_color); // 設置為透明色,若注釋掉該行則輸出綠色的圖
}
// imageinterlace 激活或禁止隔行掃描
if($type=='jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
$imagefun = 'image'.($type=='jpg' ? 'jpeg' : $type);
//imagejpeg imagegif imagepng
if(empty($filename)) $filename = substr($image, 0, strrpos($image, '.')).$suffix.'.'.$type; //獲取文件名
//aaa.gif aaa_thumb.gif
$imagefun($thumbimg, $filename); //新建圖像
imagedestroy($thumbimg); //銷毀縮略圖
imagedestroy($srcimg); //銷毀源圖
return $filename;
}
//watermark(源圖,生成文件,生成位置,水印文件,水印文本,背景色)
function watermark($source, $target = '', $w_pos = 0, $w_img = '', $w_text = '', $w_font = 12, $w_color = '#cccccc')
{
if(!$this->watermark_enable || !$this->check($source)) return false;
if(!$target) $target = $source;
if ($w_img == '' && $w_text == '')
$w_img = $this->w_img;
$source_info = getimagesize($source);
$source_w = $source_info[0]; //獲取寬
$source_h = $source_info[1]; //獲取高
if($source_w < $this->w_minwidth || $source_h < $this->w_minheight) return false; //寬和高達不到要求直接返回
switch($source_info[2]) //新建圖片
{
case 1 :
$source_img = imagecreatefromgif($source);
break;
case 2 :
$source_img = imagecreatefromjpeg($source);
break;
case 3 :
$source_img = imagecreatefrompng($source);
break;
default :
return false;
}
if(!empty($w_img) && file_exists($w_img)) //水印文件
{
$ifwaterimage = 1; //是否水印圖
$water_info = getimagesize($w_img); //水印信息
$width = $water_info[0];
$height = $water_info[1];
switch($water_info[2])
{
case 1 :
$water_img = imagecreatefromgif($w_img);
break;
case 2 :
$water_img = imagecreatefromjpeg($w_img);
break;
case 3 :
$water_img = imagecreatefrompng($w_img);
break;
default :
return;
}
}
else
{
$ifwaterimage = 0;
//imagettfbbox 本函數計算並返回一個包圍著 TrueType 文本范圍的虛擬方框的像素大小。
//imagettfbbox ( 字體大小, 字體角度, 字體文件,文件 )
$temp = imagettfbbox(ceil($w_font*1.2), 0, $this->fontfile, $w_text);//取得使用 truetype 字體的文本的范圍
$width = $temp[4] - $temp[6]; //右上角 X 位置 - 左上角 X 位置
$height = $temp[3] - $temp[5]; //右下角 Y 位置- 右上角 Y 位置
unset($temp);
}
switch($w_pos)
{
case 0: //隨機位置
$wx = rand(0,($source_w - $width));
$wy = rand(0,($source_h - $height));
break;
case 1: //左上角
$wx = 5;
$wy = 5;
break;
case 2: //上面中間位置
$wx = ($source_w - $width) / 2;
$wy = 0;
break;
case 3: //右上角
$wx = $source_w - $width;
$wy = 0;
break;
case 4: //左面中間位置
$wx = 0;
$wy = ($source_h - $height) / 2;
break;
case 5: //中間位置
$wx = ($source_w - $width) / 2;
$wy = ($source_h - $height) / 2;
break;
case 6: //底部中間位置
$wx = ($source_w - $width) / 2;
$wy = $source_h - $height;
break;
case 7: //左下角
$wx = 0;
$wy = $source_h - $height;
break;
case 8: //右面中間位置
$wx = $source_w - $width;
$wy = ($source_h - $height) /2;
break;
case 9: //右下角
$wx = $source_w - $width;
$wy = $source_h - $height ;
break;
default: //隨機
$wx = rand(0,($source_w - $width));
$wy = rand(0,($source_h - $height));
break;
}
if($ifwaterimage) //如果有水印圖
{
//imagemerge 拷貝並合並圖像的一部分
//參數(源圖,水印圖,拷貝到源圖x位置,拷貝到源圖y位置,從水印圖x位置,從水印圖y位置,高,寬,透明度)
imagemerge($source_img, $water_img, $wx, $wy, 0, 0, $width, $height, $this->w_pct);
}
else
{
if(!empty($w_color) && (strlen($w_color)==7))
{
$r = hexdec(substr($w_color,1,2)); //獲取紅色
$g = hexdec(substr($w_color,3,2)); //獲取綠色
$b = hexdec(substr($w_color,5)); //獲取藍色
}
else
{
return;
}
//imagecolorallocate 基於調色板的圖像填充背景色
//imagestring 水平地畫一行字元串
//imagestring(源圖,字體大小,位置X,位置Y,文字,顏色)
//參數($image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text)
imagettftext($source_img,$w_font,0,$wx,$wy,imagecolorallocate($source_img,$r,$g,$b),$this->fontfile,$w_text);
//imagestring($source_img,$w_font,$wx,$wy,$w_text,imagecolorallocate($source_img,$r,$g,$b));
}
//輸出到文件或者瀏覽器
switch($source_info[2])
{
case 1 :
imagegif($source_img, $target); //以 GIF 格式將圖像輸出到瀏覽器或文件
break;
case 2 :
imagejpeg($source_img, $target, $this->w_quality); //以 JPEG 格式將圖像輸出到瀏覽器或文件
break;
case 3 :
imagepng($source_img, $target); //以 PNG 格式將圖像輸出到瀏覽器或文件
break;
default :
return;
}
if(isset($water_info))
{
unset($water_info); //銷毀
}
if(isset($water_img))
{
imagedestroy($water_img); //銷毀
}
unset($source_info);
imagedestroy($source_img);
return true;
}
//gd庫必須存在,後綴為jpg|jpeg|gif|png,文件存在,imagecreatefromjpeg或者imagecreatefromgif存在
function check($image)
{
return extension_loaded('gd') &&
preg_match("/\.(jpg|jpeg|gif|png)/i", $image, $m) &&
file_exists($image) &&
function_exists('imagecreatefrom'.($m[1] == 'jpg' ? 'jpeg' : $m[1]));
//imagecreatefromjpeg
//imagecreatefromgif
//imagecreatefrompng
}
}

/**
縮略圖
1.新建一個圖像資源 通過 imagecreatefromgif imagecreatefromjpeg imagecreatefrompng
2.imageresampled 拷貝圖像,並調整大小

水印:圖片水印,文字水印
1. 創建圖像
2.加水印
圖片水印:imagemerge 把2張圖合並在一起
文字水印:imagettftext 向圖像寫入文字

*/
?>

㈥ PHP 圖片處理

圖片路徑一定要基於當前php運行所在的路徑去寫,./圖片 是當前目錄,../圖片 是上級目錄,注意規范

㈦ PHP的值返回HTML顯示

給你一段我以前用的,需要載入 jquery.min.js

login.php

<?php
header("Content-Type:text/html;charset=gb2312");

?>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<metaname="viewport"content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>

<title>xxxxx公司</title>
<style>
body{font:normal100%Helvetica,Arial,sans-serif;margin:0px;text-align:left;background:#FFF;height:100%;overflow:auto;}
table{border-collapse:collapse;}
a:link,a:visited,a:active,a:hover{color:#000;font-family:Arial,Helvetica,sans-serif;}
.linear{
FILTER:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#fff,endColorStr=#aaaaff);/*IE678*/
background:-ms-linear-gradient(top,#fff,#aaaaff);/*IE10*/
background:-moz-linear-gradient(top,#b8c4cb,#f6f6f8);/*火狐*/
background:-webkit-gradient(linear,0%0%,0%100%,from(#fff),to(#aaaaff));/*谷歌*/
background:-webkit-gradient(linear,0%0%,0%100%,from(#fff),to(#aaaaff));/*Safari4-5,Chrome1-9*/
background:-webkit-linear-gradient(top,#fff,#aaaaff);/*Safari5.1Chrome10+*/
background:-o-linear-gradient(top,#fff,#aaaaff);/*Opera11.10+*/
}
</style>
<scripttype="text/javascript"src="./js/jquery.min.js"></script>

<script>
varpsw_count=0
functionlogin_sys(){
if($.trim($("#gh_id").val())==""||$.trim($("#psd_id").val())==""){
$("#tips_message").html("工號和密碼都不能空");
return;
}

varreg=/^(w|_)*$/;
varaaa=reg.test($.trim($("#gh_id").val()));
if(!aaa){
$("#tips_message").html("工號和密碼的格式只能是英文數字");
return;

}
$("#tips_message").html("請稍侯....");
if(psw_count<4){
$.ajax({
type:"post",//使用post方法訪問後台
dataType:"text",//返回text格式的數據
url:"ver_user.php",//要訪問的後台地址
data:{find_gh:$.trim($("#gh_id").val()),cur_psw:$.trim($("#psd_id").val())},
async:false,
success:function(msg){//msg為返回的數據
if(msg>0){
$("#tips_message").html("用戶名或密碼錯誤("+psw_count+")");

}else{
$("#tips_message").html("用戶名或密碼正確");
window.location.href="index.php";
}
}
});
psw_count=psw_count+1
}else{
$("#tips_message").html("錯誤超過3次,請查對");
$("#login_btn").hide();
}

}
functionlogin_sys_admin(){

window.location.href="admin_login.php";

}
</script>
</head>
<body>

<tablealign="center"border="1"cellpadding="0"cellspacing="1"bordercolor="#d1d1d1">
<tr><thcolspan="2"align="center"class="linear"style="font-family:華文中宋;color:red;font-size:1.8em"></br>利生廠員工查詢系統歡迎您</br></br></th></tr>
<tr><tdcolspan="2">&nbsp</td></tr>

<trfont-size="12"><td>今天是:</td><td><?=gmdate("Y年n月j日",time()+8*3600)?></td></tr>
<tr><tdcolspan="2">&nbsp</td></tr>
<tr><td>工號:</td><td><inputtype="text"class="input_text"id="gh_id"name="gh"size="16"title="不能為空且不能有空格,只能英文數字"value=""/></td></tr>
<tr><td>密碼:</td><td><inputtype="password"class="input_text"id="psd_id"name="acc-code"size="8"title="不能為空且不能有空格,只能英文數字"value=""/>(4-6位英數)</td></tr>

<tr><td>驗證碼</td><td>&nbsp</td></tr>

<tr><tdcolspan="2"align="center"><spanid="tips_message"style="font-family:華文中宋;color:red;">&nbsp</span></td></tr>
<tr><tdcolspan="2"align="center"><inputid="login_btn"type="button"onclick="login_sys()"style="width:100px"value="登錄"/></td></tr>
<tr><tdcolspan="2"align="center">----------</td></tr>
<tr><tdcolspan="2"align="center">
<inputid="login_btn"type="button"onclick="login_sys_admin()"style="width:100px"value="系統操作員登錄"/>

</td></tr>

</table>

</body>
</html>

ver_user.php

<?
session_start();

header("Content-Type:text/html;charset=gb2312");
$myconn=odbc_connect("VFP_SYS_FTB","","");

$strSql="select`gh`,`yg_name`,`acc_code`,`fenchang`,`work_type`from`.lishenggh`wherelz=.f.andgh='$find_gh'";

$result=odbc_do($myconn,$strSql);
$gh="";
$yg_name="";
$acc_code="";
$fenchang="";

while(odbc_fetch_row($result))//通過循環讀取數據內容
{
$gh=odbc_result($result,1);
$yg_name=odbc_result($result,2);
$acc_code=odbc_result($result,3);
$fenchang=odbc_result($result,4);
$work_type=odbc_result($result,5);

}
odbc_close($myconn);
if($gh){
if(trim($cur_psw)==trim($acc_code)){
$_SESSION['gh']=$gh;
$_SESSION['yg_name']=$yg_name;
$_SESSION['acc_code']=$acc_code;
$_SESSION['fenchang']=$fenchang;
$_SESSION['work_type']=$work_type;
switch($_SESSION['fenchang']){
case0:
$_SESSION['fch_name']="生產";
break;
case1:
$_SESSION['fch_name']="後勤";

break;
case2:
$_SESSION['fch_name']="行政";

break;
}
echo"0";
}else{
echo"1";

}

}else{
echo"2";

}

?>

㈧ php上傳圖片的問題!

首先在php的目錄下,建一個images的文件夾

把以代碼另存為upload.php
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>PHP Code
<?php
//define a maxim size for the uploaded images
define ("MAX_SIZE","10000000");
// define the width and height for the thumbnail
// note that theese dimmensions are considered the maximum dimmension and are not fixed,
// because we have to keep the image ratio intact or it will be deformed
define ("WIDTH","170");
define ("HEIGHT","120");

// this is the function that will create the thumbnail image from the uploaded image
// the resize will be done considering the width and height defined, but without deforming the image
function make_thumb($img_name,$filename,$new_w,$new_h)
{
//get image extension.
$ext=getExtension($img_name);
//creates the new image using the appropriate function from gd library
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);

if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);

//gets the dimmensions of the image
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);

// next we will calculate the new dimmensions for the thumbnail image
// the next steps will be taken:
// 1. calculate the ratio by dividing the old dimmensions with the new ones
// 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
// and the height will be calculated so the image ratio will not change
// 3. otherwise we will use the height ratio for the image
// as a result, only one of the dimmensions will be from the fixed ones
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}

// we create a new image with the new dimmensions
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

// resize the big image to the new created one
imageresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

// output the created image to the file. Now we will have the thumbnail into the file named by $filename
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);

//destroys source and destination images.
imagedestroy($dst_img);
imagedestroy($src_img);
}

// This function reads the extension of the file.
// It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

// This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded.
$errors=0;
// checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
// if it is not empty
if ($image)
{
// get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);

// get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
// if it is not a known extension, we will suppose it is an error, print an error message
//and will not upload the file, otherwise we continue
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
// get the size of the image in bytes
// $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($sizekb > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
$copied = ($_FILES['image']['tmp_name'], $newname);
//we verify if the image has been uploaded, and print error instead
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
// the new thumbnail image will be placed in images/thumbs/ folder
$thumb_name='images/'.$image_name;
// call the function that will create the thumbnail. The function will get as parameters
//the image name, the thumbnail name and the width and height desired for the thumbnail
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}
//If no errors registred, print the success message and show the thumbnail image created
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Thumbnail created Successfully!</h1>";
echo '<img src="'.$thumb_name.'">';
}
?>

閱讀全文

與phphtmltoimage相關的資料

熱點內容
局城網中網路列印伺服器如何設置 瀏覽:444
葉子媚演過尺較大的電影 瀏覽:572
pdf裁邊 瀏覽:193
林正英和大傻演的電影叫什麼 瀏覽:797
搶先電影社區 瀏覽:754
kpzz5. top/ index. php 瀏覽:208
繁殖食人族的電影 瀏覽:488
益智類電影小學 瀏覽:828
電線平方數演算法 瀏覽:197
有一個電影男主叫馬克 瀏覽:779
韓國,補課電影演員表 瀏覽:182
linux查看系統命令是什麼 瀏覽:32
matlab歷史命令 瀏覽:219
主角穿越到工作細胞的小說 瀏覽:102
九十年代香港老太太鬼電影 瀏覽:871
特工劉堅是李連傑的哪部電影 瀏覽:334
極坐標運演算法則 瀏覽:605
十大香港全漏電影 瀏覽:335
小虎還鄉裡面的驢叫什麼 瀏覽:499
誰有小電影網址啊 瀏覽:376