首页 > 编程技术 > php

php截屏代码

发布时间:2016-11-25 16:59

php截屏代码

<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.111cn.net");

/* Still working? */
while ($browser->Busy) {
    com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
?>

php 图片 中文验证码

<img" width=100% src="verify_image.php" alt="点此刷新验证码" name="verify_code" width="65" height="20" border="0" id="verify_code" onclick="document.getElementById('verify_code').src='verify_image.php?'+Math.random();" style="cursor:pointer;" />

<?php
session_start();

$vi = new vCodeImage;
$vi->SetImage(1,4,65,20,80,1);

class vCodeImage{
 var $mode;  //1:数字模式,2:字母模式,3:数字字母模式,其他:数字字母优化模式
 var $v_num;  //验证码个数
 var $img_w;  //验证码图像宽度
 var $img_h;  //验证码图像高度
 var $int_pixel_num;  //干扰像素个数
 var $int_line_num;  //干扰线条数
 var $font_dir;   //字体文件相对路径
 var $border;   //图像边框
 var $borderColor;  //图像边框颜色

 function SetImage($made,$v_num,$img_w,$img_h,$int_pixel_num,$int_line_num,$font_dir='../font',$border=true,$borderColor='255,200,85'){
  if(!isset($_SESSION['vCode'])){
   session_register('vCode');
  }
  $_SESSION['vCode']="";
 
  $this->mode = $made;
  $this->v_num = $v_num;
  $this->img_w = $img_w;
  $this->img_h = $img_h;
  $this->int_pixel_num = $int_pixel_num;
  $this->int_line_num = $int_line_num;
  $this->font_dir = $font_dir;
  $this->border = $border;
  $this->borderColor = $borderColor;
  $this->GenerateImage();
 }

 function GetChar($mode){
  if($mode == "1"){
   $ychar = "0,1,2,3,4,5,6,7,8,9";
  }
  else if($mode == "2"){
   $ychar = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
  }
  else if($mode == "3"){
   $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
  }
  else
   $ychar = "3,4,5,6,7,8,9,A,B,C,D,H,K,P,R,S,T,W,X,Y";
  return $ychar;
 }
 
 function RandColor($rs,$re,$gs,$ge,$bs,$be){
  $r = mt_rand($rs,$re);
  $g = mt_rand($gs,$ge);
  $b = mt_rand($bs,$be);
  return array($r,$g,$b);
 }
 
 function GenerateImage(){
  $im = imagecreate($this->img_w,$this->img_h);

  $black = imagecolorallocate($im, 0,0,0);
  $white = imagecolorallocate($im, 255,255,255);
  $bgcolor = imagecolorallocate($im, 250,250,250);

  imagefill($im,0,0,$bgcolor);

  $fonts = ScanDir($this->font_dir);
  $fmax = count($fonts) - 2;

  $ychar = $this->GetChar($this->mode);
  $list = explode(",",$ychar);

  $x = mt_rand(2,$this->img_w/($this->v_num+2));
  $cmax = count($list) - 1;

  $v_code = '';

  for($i=0;$i<$this->v_num;$i++) //验证码
  {
   $randnum = mt_rand(0,$cmax);
   $this_char = $list[$randnum];
   $v_code .= $this_char;
   $size = mt_rand(intval($this->img_w/5),intval($this->img_w/4));
   $angle = mt_rand(-20,20);
   $y = mt_rand(($size+2),($this->img_h-2));
   if($this->border)
    $y = mt_rand(($size+3),($this->img_h-3));
   $rand_color = $this->RandColor(0,200,0,100,0,250);
   $randcolor = imagecolorallocate($im,$rand_color[0],$rand_color[1],$rand_color[2]);
   $fontrand = mt_rand(2, $fmax);
   $font = "$this->font_dir/".$fonts[$fontrand];
   imagettftext($im, $size, $angle, $x, $y, $randcolor, $font, $this_char);
   $x = $x + intval($this->img_w/($this->v_num+1));
  }

  for($i=0;$i<$this->int_pixel_num;$i++){//干扰像素
   $rand_color = $this->RandColor(50,250,0,250,50,250);
   $rand_color_pixel = imagecolorallocate($im,$rand_color[0],$rand_color[1],$rand_color[2]);
   imagesetpixel($im, mt_rand()%$this->img_w, mt_rand()%$this->img_h, $rand_color_pixel);
  }

  for($i=0;$i<$this->int_line_num;$i++){ //干扰线
   $rand_color = $this->RandColor(0,250,0,250,0,250);
   $rand_color_line = imagecolorallocate($im,$rand_color[0],$rand_color[1],$rand_color[2]);
   imageline($im, mt_rand(0,intval($this->img_w/3)), mt_rand(0,$this->img_h), mt_rand(intval($this->img_w - ($this->img_w/3)),$this->img_w), mt_rand(0,$this->img_h), $rand_color_line);
  }

  if($this->border) //画出边框
  {
   if(preg_match("/^\d{1,3},\d{1,3},\d{1,3}$/",$this->borderColor)){
    $borderColor = explode(',',$this->borderColor);
   }
   $border_color_line = imagecolorallocate($im,$borderColor[0],$borderColor[1],$borderColor[2]);
   imageline($im, 0, 0, $this->img_w, 0, $border_color_line); //上横
   imageline($im, 0, 0, 0, $this->img_h, $border_color_line); //左竖
   imageline($im, 0, $this->img_h-1, $this->img_w, $this->img_h-1, $border_color_line); //下横
   imageline($im, $this->img_w-1, 0, $this->img_w-1, $this->img_h, $border_color_line); //右竖
  }

  imageantialias($im,true); //抗锯齿

  $time = time();
  $_SESSION['vCode'] = $v_code."|".$time; //把验证码和生成时间负值给$_SESSION[vCode]

  //生成图像给浏览器
  if (function_exists("imagegif")) {
      header ("Content-type: image/gif");
      imagegif($im);
  }
  elseif (function_exists("imagepng")) {
      header ("Content-type: image/png");
      imagepng($im);
  }
  elseif (function_exists("imagejpeg")) {
      header ("Content-type: image/jpeg");
      imagejpeg($im, "", 80);
  }
  elseif (function_exists("imagewbmp")) {
      header ("Content-type: image/vnd.wap.wbmp");
      imagewbmp($im);
  }
  else
      die("No Image Support On This Server !");
 
  imagedestroy($im);
 }
}
?>


<?
/**
* 生成缩略图
* $srcName----为原图片路径
* $newWidth,$newHeight----分别缩略图的最大宽,高
* $newName----为缩略图文件名(含路径),默认为加入thumbnail
* @param string $srcName
* @param int $newWidth
* @param int $newHeight
* @param string $newName
* return viod
*/
function resizeImg($srcName,$newWidth,$newHeight,$newName=""
)
{
        if(
$newName==""
)
        {
                
$nameArr=explode('.',$srcName
);
                
$expName=array_pop($nameArr
);
                
$expName='thumbnail.'.$expName
;
                
array_push($nameArr,$expName
);
                
$newName implode('.',$nameArr
);
        }
        
$info ""
;
        
$data getimagesize($srcName,$info
);
        switch (
$data[2
])
        {
                case 
1
:
                        if(!
function_exists("imagecreatefromgif"
)){
                                echo 
"你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!返回"
;
                                exit();
                        }
                        
$im ImageCreateFromGIF($srcName
);
                        break;
                case 
2
:
                        if(!
function_exists("imagecreatefromjpeg"
)){
                                echo 
"你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!返回"
;
                                exit();
                        }
                        
$im ImageCreateFromJpeg($srcName
);
                        break;
                case 
3
:
                        
$im ImageCreateFromPNG($srcName
);
                        break;
        }
        
$srcW=ImageSX($im
);
        
$srcH=ImageSY($im
);
        
$newWidthH=$newWidth/$newHeight
;
        
$srcWH=$srcW/$srcH
;
        if(
$newWidthH<=$srcWH
){
                
$ftoW=$newWidth
;
                
$ftoH=$ftoW*($srcH/$srcW
);
        }
        else{
                
$ftoH=$newHeight
;
                
$ftoW=$ftoH*($srcW/$srcH
);
        }
        if(
$srcW>$newWidth||$srcH>$newHeight
)
        {
                if(
function_exists("imagecreatetruecolor"
))
                {
                        @
$ni ImageCreateTrueColor($ftoW,$ftoH
);
                        if(
$niImageCopyResampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH
);
                        else
                        {
                                
$ni=ImageCreate($ftoW,$ftoH
);
                                
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH
);
                        }
                }
                else
                {
                        
$ni=ImageCreate($ftoW,$ftoH
);
                        
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH
);
                }
                if(
function_exists('imagejpeg')) ImageJpeg($ni,$newName
);
                else 
ImagePNG($ni,$newName
);
                
ImageDestroy($ni
);
        }
        
ImageDestroy($im
);
}

resizeImg('123.JPG',150,150
);
?>


php+mysql 图象输入输出


我看了网上的例子~用了~发现图片进数据库没问题~但是关于输出部分总是报错~
代码如下
建库:
CREATE TABLE Images ( PicNum int NOT NULL AUTO_INCREMENT PRIMARY KEY, Image BLOB );
进库:<?php
     $Picture=$_POST[file];   //flie是 我那个图片上传页的表单的传递
         If($Picture != "none")
         { $PSize = filesize($Picture);
         $mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize));
         mysql_connect("localhost","root","") or die("Unable to connect to SQL server");
         @mysql_select_db("mymg") or die("Unable to select database");
         mysql_query("INSERT INTO images (image) VALUES ('$mysqlPicture')") or die("Cant Perform Query"); }
         else
         { echo"You did not upload any picture"; }
         ?>
程序到这里都没问题~我用CMD看了下 数据库里也有东西.
输出:
<html>
<body>
<?php
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$result=mysql_query("SELECT * FROM Images") or die("Cant Perform Query");
While($row=mysql_fetch_object($result))
                { echo "<IMG SRC='Second.php ? PicNum=$row- > PicNum'/>"};!                 ?>
                 </body>
                 </html>
'Second.php:
          <?php
$result=mysql_query("SELECT * FROM Images WHERE PicNum=$PicNum") or die("Cant perform Query");
$row=mysql_fetch_object($result);
Header( "Content-type: image/gif");
echo $row->image;
?>
一直想在网上找个图片所略图程序,但是一直没有找到无变形的,一般都是对原图进行简单的缩放。
我想也许已经有了,只是我没有找到,所以没办法自己写了一个,其实也不是全是自己写的,只是
在已有的基础上改的!
源码如下:

<?php
/*
*版权说明:该版本是在“IEB_UPLOAD CLASS Ver 1.1”的基础上二次开发的,原程序对
*图片的裁剪将使图片变形、失真!本人在该程序的基础上进行了更改,用数据参数与原图片
*文件参数(主要是指宽和高)进行对比,得出比例值,先生成与原图片同比例缩放的图片,然
*后再以该中间图中心开始截取,从而获得缩略图,当然,图片会被裁剪,但是是最小限度的
*裁剪!
*程序设计:swin.wang  Email: php_in_china@yahoo.com.cn QQ:592298893
*
*该程序你可无限制使用,但请保留版权信息
×
×使用犯法:
*        $upfos = new ieb_upload('photo_file','./up_img'); photo_file 表单文件域名称,不要加$; ./up_img,上传位置
*        $old_file_name=$upfos -> getName();
*        $old_file_fooder=$upfos -> getExt();
*        $file_size=$upfos -> getSize();
*        $file_name=$upfos -> newName();
*        $upfos -> upload($file_name);
*        $upfos -> thumb("small_",125,120);
*        $new_file_name=$upfos -> UpFile(); $new_file_name 上传后大图名
×        $small_file_name="small_".$new_file_name;  $small_file_name 所略图名
*/
class ieb_upload{
var $FormName; //文件域名称
var $Directroy; //上传至目录
var $MaxSize; //最大上传大小
var $CanUpload; //是否可以上传
var $doUpFile; //上传的文件名
var $sm_File; //缩略图名称
var $Error;  //错误参数

function ieb_upload($formName='', $dirPath='', $maxSize=2097152) //(1024*2)*1024=2097152 就是 2M
{
  global $FormName, $Directroy, $MaxSize, $CanUpload, $Error, $doUpFile, $sm_File;
  //初始化各种参数
  $FormName = $formName;
  $MaxSize = $maxSize;
  $CanUpload = true;
  $doUpFile = '';
  $sm_File = '';
  $Error = 0;
  
  if ($formName == ''){
   $CanUpload = false;
   $Error = 1;
   break;
   }
  
  if ($dirPath == ''){
   $Directroy = $dirPath;
  }else{
   $Directroy = $dirPath.'/';
  }
}

//检查文件是否存在
function scanFile()
{
  global $FormName, $Error, $CanUpload;
  
  if ($CanUpload){
  
   $scan = is_readable($_FILES[$FormName]['name']);
   
   if ($scan){   
    $Error = 2;
   }
   
   return $scan;
  }
}


//获取文件大小
function getSize($format = 'B')
{
  global $FormName, $Error, $CanUpload;
  
  if ($CanUpload){
  
   if ($_FILES[$FormName]['size'] == 0){
    $Error = 3;
    $CanUpload = false;
   }
   
   switch ($format){
   case 'B':
   return $_FILES[$FormName]['size'];
   break;
   
   case 'M':
   return ($_FILES[$FormName]['size'])/(1024*1024);
   }
   
  }
}

//获取文件类型
function getExt()
{
  global $FormName, $Error, $CanUpload;
  
  if ($CanUpload){
   $ext=$_FILES[$FormName]['name'];
   $extStr=explode('.',$ext);
   $count=count($extStr)-1;
  }
  return $extStr[$count];
}

//获取文件名称
function getName()
{
  global $FormName, $CanUpload;
  
  if ($CanUpload){
   return $_FILES[$FormName]['name'];
  }
}

//新建文件名
function newName()
{
  global $CanUpload, $FormName;
  
  if ($CanUpload){
   $FullName=$_FILES[$FormName]['name'];
   $extStr=explode('.',$FullName);
   $count=count($extStr)-1;
   $ext = $extStr[$count];
   
   return date('YmdHis').rand(0,9).'.'.$ext;
  }
}

//上传文件
function upload($fileName = '')
{
  global $FormName, $Directroy, $CanUpload, $Error, $doUpFile;
  
  if ($CanUpload){
   if ($_FILES[$FormName]['size'] == 0){
    $Error = 3;
    $CanUpload = false;
    return $Error;
    break;
   }
  }
  
  if($CanUpload){
  
   if ($fileName == ''){
    $fileName = $_FILES[$FormName]['name'];
   }
      
   $doUpload=@copy($_FILES[$FormName]['tmp_name'], $Directroy.$fileName);
   
   if($doUpload)
   {
    $doUpFile = $fileName;
    chmod($Directroy.$fileName, 0777);
    return true;
   }else{
    $Error = 4;
    return $Error;
   }
  }
}

//创建图片缩略图
function thumb($dscChar='',$width=160,$height=120)
{
  global $CanUpload, $Error, $Directroy, $doUpFile, $sm_File;
  
  if ($CanUpload && $doUpFile != ''){
   $srcFile = $doUpFile;
   
   if ($dscChar == ''){
    $dscChar = 'sm_';
   }
   
   $dscFile = $Directroy.$dscChar.$srcFile;
   $data = getimagesize($Directroy.$srcFile,&$info);
   
   switch ($data[2]) {
   case 1:
   $im = @imagecreatefromgif($Directroy.$srcFile);
   break;
   
   case 2:
   $im = @imagecreatefromjpeg($Directroy.$srcFile);
   break;
   
   case 3:
   $im = @imagecreatefrompng($Directroy.$srcFile);
   break;
   }
   
   $srcW=imagesx($im);
   $srcH=imagesy($im);
   
   if(($srcW/$width)>=($srcH/$height)){
                $temp_height=$height;
                $temp_width=$srcW/($srcH/$height);
                $src_X=abs(($width-$temp_width)/2);
                $src_Y=0;
        }
        else{
                $temp_width=$width;
                $temp_height=$srcH/($srcW/$width);
                $src_X=0;
                $src_Y=abs(($height-$temp_height)/2);
                }
        $temp_img=imagecreatetruecolor($temp_width,$temp_height);
        imagecopyresized($temp_img,$im,0,0,0,0,$temp_width,$temp_height,$srcW,$srcH);
       
       
        $ni=imagecreatetruecolor($width,$height);
        imagecopyresized($ni,$temp_img,0,0,$src_X,$src_Y,$width,$height,$width,$height);
        $cr = imagejpeg($ni,$dscFile);
           chmod($dscFile, 0777);
          
  
   if ($cr){
    $sm_File = $dscFile;
    return true;
   }else{
    $Error = 5;
    return $Error;
   }
  }
}

//显示错误参数
function Err(){
  global $Error;
  return $Error;
}

//上传后的文件名
function UpFile(){
  global $doUpFile, $Error;
  if ($doUpFile != ''){
   return $doUpFile;
  }else{
   $Error = 6;
  }
}

//上传文件的路径
function filePath(){
  global $Directroy, $doUpFile, $Error;
  if ($doUpFile != ''){
   return $Directroy.$doUpFile;
  }else{
   $Error = 6;
  }  
}

//缩略图文件名称
function thumbMap(){
  global $sm_File, $Error;
  if ($sm_File != ''){
   return $sm_File;
  }else{
   $Error = 6;
  }
}

//显示版本信息
function ieb_version(){
  return 'swin img class Ver 0.1';
}
}
?>
标签:[!--infotagslink--]

您可能感兴趣的文章: