php 图片下载程序

 更新时间:2016年11月25日 16:58  点击:2271
php 图片下载程序

function displayimg($image)
 {
  $image = './upload/'.imgdecode($image);
  //echo $image;exit;
  if (file_exists($image))
  {
   $info = getimagesize($image);
   header("Content-type:$info[mime]");
   switch ($info[2])
   {
    case 1:  $cimage = imagecreatefromgif($image);
       imagegif($cimage);
       imagedestroy($cimage);
       break;
    case 2:  $cimage = imagecreatefromjpeg($image);
       imagejpeg($cimage);
       imagedestroy($cimage);
       break;
    case 3:  $cimage = imagecreatefrompng($image);
       imagepng($cimage);
       imagedestroy($cimage);
       break;
    case 6:  $cimage = imagecreatefromwbmp($image);
       imagewbmp($cimage);
       imagedestroy($cimage);
       break;
   }
   echo $simage;
  }
  else
  {
   header("HTTP/1.0 404 Not Found");
  }
 }

php 验证码生成程序[可自动判断php gd库]
function ShowKey()
{
$key=strtolower(domake_password(4));
$set=esetcookie("checkkey",$key);
 //是否支持gd库
if (function_exists("imagejpeg")) {
   header ("Content-type: image/jpeg");
   $img=imagecreate(69,20);
   $black=imagecolorallocate($img,255,255,255);
   $gray=imagecolorallocate($img,102,102,102);
   imagefill($img,0,0,$gray);
   imagestring($img,3,14,3,$key,$black);
   imagejpeg($img);
   imagedestroy($img);
}
elseif (function_exists("imagegif")) {
   header ("Content-type: image/gif");
   $img=imagecreate(69,20);
   $black=imagecolorallocate($img,255,255,255);
   $gray=imagecolorallocate($img,102,102,102);
   imagefill($img,0,0,$gray);
   imagestring($img,3,14,3,$key,$black);
   imagegif($img);
   imagedestroy($img);
}
elseif (function_exists("imagepng")) {
 header ("Content-type: image/png");
   $img=imagecreate(69,20);
   $black=imagecolorallocate($img,255,255,255);
   $gray=imagecolorallocate($img,102,102,102);
   imagefill($img,0,0,$gray);
   imagestring($img,3,14,3,$key,$black);
   imagepng($img);
   imagedestroy($img);
}
elseif (function_exists("imagewbmp")) {
 header ("Content-type: image/vnd.wap.wbmp");
   $img=imagecreate(69,20);
   $black=imagecolorallocate($img,255,255,255);
   $gray=imagecolorallocate($img,102,102,102);
   imagefill($img,0,0,$gray);
   imagestring($img,3,14,3,$key,$black);
   imagewbmp($img);
   imagedestroy($img);
}
else {
 $set=esetcookie("checkkey","ebak");
 @include("class/functions.php");
 echo ReadFiletext("images/ebak.jpg");
}
}
ShowKey();

php 创建图片教程,我们在编程时经常会看到用php 写图片,验证码等

<?php

$height = 300;

$width = 300;

$im = ImageCreateTrueColor($width, $height);

$white = ImageColorAllocate ($im, 255, 255, 255);

$blue = ImageColorAllocate ($im, 0, 0, 64);

ImageFill($im, 0, 0, $blue);

//ImageLine($im, 0, 0, $width, $height, $white);

ImageString($im, 10, 100, 120, 'Hello,PHP', $white);

Header ('Content-type: image/png');

ImagePng($im);

ImageDestroy($im);

?>

php 图处理函数实例教程, 图片处理,php,图片函数

<?php
//公用函数

//把角度转换为弧度
function deg2Arc($degrees) {
return($degrees * (pi()/180.0));
}

//RGB
function getRGB($color){
  $R=($color>>16) & 0xff;
  $G=($color>>8) & 0xff;
  $B=($color) & 0xff;
  return (array($R,$G,$B));
}

// 取得在椭圆心为(0,0)的椭圆上 x,y点的值
function pie_point($deg,$va,$vb){
$x= cos(deg2Arc($deg)) * $va;
$y= sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}


//3D饼图类

class chart{

var $a; //椭圆长半轴
var $b; //椭圆短半轴
var $DataArray;  //每个扇形的数据
var $ColorArray; //每个扇形的颜色 要求按照十六进制书写但前面不加0x
//为边缘及阴影为黑色

function chart($pa=100,$pb=60,$sData="100,200,300,400,500,300", $sColor="ee00ff,dd0000,cccccc,ccff00,00ccff,ccff00")
{
    $this->a=$pa;
    $this->b=$pb;
    $this->DataArray=split(",",$sData);
    $this->ColorArray=split(",",$sColor);
}

function setA($v){
    $this->a=$v;
}

function getA(){
    return $this->a;
}

function setB($v){
    $this->b=$v; 
}

function getB(){
    return $this->b;
}

function setDataArray($v){
    $this->DataArray=split(",",$v);
}

function getDataArray($v){
    return $this->DataArray;
}

function setColorArray($v){
    $this->ColorArray=split(",",$v);
}

function getColorArray(){
    return  $this->ColorArray;
}

 
function  DrawPie(){
    $image=imagecreate($this->a*2+40,$this->b*2+40);
    $PieCenterX=$this->a+10;
    $PieCenterY=$this->b+10;
    $DoubleA=$this->a*2;
    $DoubleB=$this->b*2;
    list($R,$G,$B)=getRGB(0);
    $colorBorder=imagecolorallocate($image,$R,$G,$B);
    $DataNumber=count($this->DataArray);
    
    //$DataTotal
    for($i=0;$i<$DataNumber;$i++)      $DataTotal+=$this->DataArray[$i]; //算出数据和
    
    //填充背境
    imagefill($image, 0, 0, imagecolorallocate($image, 0xFF, 0xFF, 0xFF));

    /*
    ** 画每一个扇形
    */
    $Degrees = 0;
    for($i = 0; $i < $DataNumber; $i++){
        $StartDegrees = round($Degrees);
        $Degrees += (($this->DataArray[$i]/$DataTotal)*360);
        $EndDegrees = round($Degrees);
        $percent = number_format($this->DataArray[$i]/$DataTotal*100, 1); 
        list($R,$G,$B)=getRGB(hexdec($this->ColorArray[$i]));
        $CurrentColor=imagecolorallocate($image,$R,$G,$B);
        if ($R>60 and $R<256)            $R=$R-60;
        if ($G>60 and $G<256)            $G=$G-60;
        if ($B>60 and $B<256)            $B=$B-60;
        $CurrentDarkColor=imagecolorallocate($image,$R,$G,$B);
        //画扇形弧
        imagearc($image,$PieCenterX,$PieCenterY,$DoubleA,$DoubleB,$StartDegrees,$EndDegrees,$CurrentColor);
        //画直线
        list($ArcX, $ArcY) = pie_point($StartDegrees , $this->a , $this->b);
        imageline($image,$PieCenterX,$PieCenterY,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY),$CurrentColor);
        //画直线
        list($ArcX, $ArcY) = pie_point($EndDegrees,$this->a , $this->b);
        imageline($image,$PieCenterX,$PieCenterY,ceil($PieCenterX + $ArcX),ceil($PieCenterY + $ArcY),$CurrentColor);
        //填充扇形
        $MidPoint = round((($EndDegrees - $StartDegrees)/2) + $StartDegrees);
        list($ArcX, $ArcY) = Pie_point($MidPoint, $this->a*3/4 , $this->b*3/4);
        
        imagefilltoborder($image,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY), $CurrentColor,$CurrentColor);
        imagestring($image,2,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),$percent."%",$colorBorder);

        //画阴影
        if ($StartDegrees>=0 and $StartDegrees<=180){
           if($EndDegrees<=180){    
               for($k = 1; $k < 15; $k++)
                imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
           }else{
               for($k = 1; $k < 15; $k++)
                imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, 180, $CurrentDarkColor);
           }

        }
   }
        
    /*到此脚本已经生了一幅图像了
    **现在需要的是把它发到浏览器上,重要的一点是要将标头发给浏览器,让它知道是一个GIF文件。不然的话你只能看到一堆奇怪的乱码
    */ 
    //输出生成的图片    
    header("Content-type: image/gif");
    imagegif($image);
    imagedestroy($image);
}//End drawPie()
}//End class


//实现

$objp = new chart();
$objp->DrawPie();
?> 

php上传图片并生成缩位图代码,我们时常要上传图片,但也要保留自己的版权所以就会用到图片加水印哦,下面的程序就是上传图片成功后再给图片加上你自己做的水印效果哦.

<?php

class Image {
 var $imageResource = NULL;
 var $target = NULL;
 var $enableTypes = array();
 var $imageInfo = array();
 var $createFunc = '';
 var $imageType = NULL;
 
 /**
  * Construct for this class
  *
  * @param string $image
  * @return Image
  */
 function Image($image = NULL) {
  //get enables
  if(imagetypes() & IMG_GIF) {
   $this->enableTypes[] = 'image/gif';
  }
  if(imagetypes() & IMG_JPEG) {
   $this->enableTypes[] = 'image/jpeg';
  }
  if (imagetypes() & IMG_JPG) {
   $this->enableTypes[] = 'image/jpg';
  }
  if(imagetypes() & IMG_PNG) {
   $this->enableTypes[] = 'image/png';
  }
  //end get
  
  if($image != NULL) {
   $this->setImage($image);
  }
 }
 
 /**
  * set a image resource
  *
  * @param string $image
  * @return boolean
  */
 function setImage($image) {
  if(file_exists($image) && is_file($image)) {
   $this->imageInfo = getimagesize($image);
   $img_mime = strtolower($this->imageInfo['mime']);
   if(!in_array($img_mime, $this->enableTypes)) {
    exit('系统不能操作这种图片类型.');
   }
   switch ($img_mime) {
    case 'image/gif':
     $link = imagecreatefromgif($image);
     $this->createFunc = 'imagegif';
     $this->imageType = 'gif';
     break;
    case 'image/jpeg':
    case 'image/jpg':
     $link = imagecreatefromjpeg($image);
     $this->createFunc = 'imagejpeg';
     $this->imageType = 'jpeg';
     break;
    case 'image/png':
     $link = imagecreatefrompng($image);
     $this->createFunc = 'imagepng';
     $this->imageType = 'png';
     break;
    default:
     $link = 'unknow';
     $this->imageType = 'unknow';
     break;
   }
   if($link !== 'unknow') {
    $this->imageResource = $link;
   } else {
    exit('这种图片类型不能改变尺寸.');
   }
   unset($link);
   return true;
  } else {
   return false;
  }
 }
 
 /**
  * set header
  *
  */
 function setHeader() {
  switch ($this->imageType) {
   case 'gif':
    header('content-type:image/gif');
    break;
   case 'jpeg':
    header('content-type:image/jpeg');
    break;
   case 'png':
    header('content-type:image/png');
    break;
   default:
    exit('Can not set header.');
    break;
  }
  return true;
 }
 
 /**
  * change the image size
  *
  * @param int $width
  * @param int $height
  * @return boolean
  */
 function changeSize($width, $height = -1) {
  if(!is_resource($this->imageResource)) {
   exit('不能改变图片的尺寸,可能是你没有设置图片来源.');
  }
  $s_width = $this->imageInfo[0];
  $s_height = $this->imageInfo[1];
  $width = intval($width);
  $height = intval($height);
  
  if($width <= 0) exit('图片宽度必须大于零.');
  if($height <= 0) {
   $height = ($s_height / $s_width) * $width;
  }
  
  $this->target = imagecreatetruecolor($width, $height);
  if(@imagecopyresized($this->target, $this->imageResource, 0, 0, 0, 0, $width, $height, $s_width, $s_height))
   return true;
  else
   return false;
 }
 
 /**
  * Add watermark
  *
  * @param string $image
  * @param int $app
  */
 function addWatermark($image, $app = 50) {
  if(file_exists($image) && is_file($image)) {
   $s_info = getimagesize($image);
  } else {
   exit($image . '文件不存在.');
  }

  $r_width = $s_info[0];
  $r_height = $s_info[1];

  if($r_width > $this->imageInfo[0]) exit('水印图片必须小于目标图片');
  if($r_height > $this->imageInfo[1]) exit('水印图片必须小于目标图片');
  
  switch ($s_info['mime']) {
   case 'image/gif':
    $resource = imagecreatefromgif($image);
    break;
   case 'image/jpeg':
   case 'image/jpg':
    $resource = imagecreatefromjpeg($image);
    break;
   case 'image/png':
    $resource = imagecreatefrompng($image);
    break;
   default:
    exit($s_info['mime'] .'类型不能作为水印来源.');
    break;
  }
  
  $this->target = &$this->imageResource;
  imagecopymerge($this->target, $resource, $this->imageInfo[0] - $r_width - 5, $this->imageInfo[1] - $r_height - 5, 0,0 ,$r_width, $r_height, $app);
  imagedestroy($resource);
  unset($resource);
 }
 
 /**
  * create image
  *
  * @param string $name
  * @return boolean
  */
 function create($name = NULL) {
  $function = $this->createFunc;
  if($this->target != NULL && is_resource($this->target)) {
   if($name != NULL) {
    $function($this->target, $name);
   } else {
    $function($this->target);
   }
   return true;
  } else if($this->imageResource != NULL && is_resource($this->imageResource)) {
   if($name != NULL) {
    $function($this->imageResource, $name);
   } else {
    $function($this->imageResource);
   }
   return true;
  } else {
   exit('不能创建图片,原因可能是没有设置图片来源.');
  }
 }
 
 /**
  * free resource
  *
  */
 function free() {
  if(is_resource($this->imageResource)) {
   @imagedestroy($this->imageResource);
  }
  if(is_resource($this->target)) {
   @imagedestroy($this->target);
  }
 }
}
?>

[!--infotagslink--]

相关文章

  • 使用PHP+JavaScript将HTML页面转换为图片的实例分享

    这篇文章主要介绍了使用PHP+JavaScript将HTML元素转换为图片的实例分享,文后结果的截图只能体现出替换的字体,也不能说将静态页面转为图片可以加快加载,只是这种做法比较interesting XD需要的朋友可以参考下...2016-04-19
  • C#开发Windows窗体应用程序的简单操作步骤

    这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
  • C#从数据库读取图片并保存的两种方法

    这篇文章主要介绍了C#从数据库读取图片并保存的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2021-01-16
  • Photoshop古装美女图片转为工笔画效果制作教程

    今天小编在这里就来给各位Photoshop的这一款软件的使用者们来说说把古装美女图片转为细腻的工笔画效果的制作教程,各位想知道方法的使用者们,那么下面就快来跟着小编一...2016-09-14
  • Python 图片转数组,二进制互转操作

    这篇文章主要介绍了Python 图片转数组,二进制互转操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-09
  • php抓取网站图片并保存的实现方法

    php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
  • C++调用C#的DLL程序实现方法

    本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
  • jquery左右滚动焦点图banner图片鼠标经过显示上下页按钮

    jquery左右滚动焦点图banner图片鼠标经过显示上下页按钮...2013-10-13
  • C#使用Process类调用外部exe程序

    本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
  • 微信小程序 页面传值详解

    这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
  • 利用JS实现点击按钮后图片自动切换的简单方法

    下面小编就为大家带来一篇利用JS实现点击按钮后图片自动切换的简单方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2016-10-25
  • Photoshop枪战电影海报图片制作教程

    Photoshop的这一款软件小编相信很多的人都已经是使用过了吧,那么今天小编在这里就给大家带来了用Photoshop软件制作枪战电影海报的教程,想知道制作步骤的玩家们,那么下面...2016-09-14
  • 使用GruntJS构建Web程序之构建篇

    大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
  • js实现上传图片及时预览

    这篇文章主要为大家详细介绍了js实现上传图片及时预览的相关资料,具有一定的参考价值,感兴趣的朋友可以参考一下...2016-05-09
  • uniapp微信小程序:key失效的解决方法

    这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
  • python opencv通过4坐标剪裁图片

    图片剪裁是常用的方法,那么如何通过4坐标剪裁图片,本文就详细的来介绍一下,感兴趣的小伙伴们可以参考一下...2021-06-04
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • 将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文

    时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25
  • 使用PHP下载CSS文件中的图片的代码

    共享一段使用PHP下载CSS文件中的图片的代码 复制代码 代码如下: <?php //note 设置PHP超时时间 set_time_limit(0); //note 取得样式文件内容 $styleFileContent = file_get_contents('images/style.css'); //not...2013-10-04
  • 微信小程序自定义tabbar组件

    这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14