php截屏代码
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 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($ni) ImageCopyResampled($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';
}
}
?>
相关文章
- 这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
- 有一种方法,可以不打开网站而直接查看到这个网站的源代码.. 这样可以有效地防止误入恶意网站... 在浏览器地址栏输入: view-source:http://...2016-09-20
- PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- 本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
- php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
- 其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
- index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
PHP中func_get_args(),func_get_arg(),func_num_args()的区别
复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04php导出csv格式数据并将数字转换成文本的思路以及代码分享
php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07- ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25