php imagecreatefromgif创建 gif图片

 更新时间:2016年11月25日 16:58  点击:2050

php imagecreatefromgif创建 gif图片

imagecreatefromgif($filename)
imagecreatefromgif()返回一个图像标识符代表从给定的文件名获得的图像

$filename是gif图片名称哦。

来看个实例

<?php
function LoadGif($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefromgif($imgname);

    /* See if it failed */
    if(!$im)
    {
        /* Create a blank image */
        $im = imagecreatetruecolor (150, 30);
        $bgc = imagecolorallocate ($im, 255, 255, 255);
        $tc = imagecolorallocate ($im, 0, 0, 0);

        imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);

        /* Output an error message */
        imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

header('Content-Type: image/gif');

$img = LoadGif('bogus.image');

imagegif($img);
imagedestroy($img);
?>

<?php教程
 
class My_Lib_simpleimage {
 var $image;
 var $image_type;
 function load($filename) { 
    //$filename 文件的临时文件名 $_FILES['name']['tmp_name']
  $image_info = getimagesize($filename);
  $this->image_type = $image_info[2];
  if( $this->image_type == IMAGETYPE_JPEG ) {
  $this->image = imagecreatefromjpeg($filename);
  } elseif( $this->image_type == IMAGETYPE_GIF ) {
  $this->image = imagecreatefromgif($filename);
  } elseif( $this->image_type == IMAGETYPE_PNG ) {
  $this->image = imagecreatefrompng($filename);
  }
 }
 
 function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
  if( $image_type == IMAGETYPE_JPEG ) {
  imagejpeg($this->image,$filename,$compression);
  } elseif( $image_type == IMAGETYPE_GIF ) {
  imagegif($this->image,$filename);
  } elseif( $image_type == IMAGETYPE_PNG ) {
  imagepng($this->image,$filename);
  }
  if( $permissions != null) {
  chmod($filename,$permissions);
  }
 }
 function output($image_type=IMAGETYPE_JPEG) {
  if( $image_type == IMAGETYPE_JPEG ) {
  imagejpeg($this->image);
  } elseif( $image_type == IMAGETYPE_GIF ) {
  imagegif($this->image);
  } elseif( $image_type == IMAGETYPE_PNG ) {
  imagepng($this->image);
  }
 }
 function getWidth() {
  return imagesx($this->image);
 }
 function getHeight() {
  return imagesy($this->image);
 }
 
 #设置缩略图片高度
 function resizeToHeight($height) {
  $ratio = $height / $this->getHeight();
  $width = $this->getWidth() * $ratio;
  $this->resize($width,$height);
 }
 #设置缩略图片宽度
 function resizeToWidth($width) {
  $ratio = $width / $this->getWidth();
  $height = $this->getheight() * $ratio;
  $this->resize($width,$height);
 }
 function scale($scale) {
  $width = $this->getWidth() * $scale/100;
  $height = $this->getheight() * $scale/100;
  $this->resize($width,$height);
 }
 function resize($width,$height) {
  $new_image = imagecreatetruecolor($width, $height);
  imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
  $this->image = $new_image;
 }
}
?>

php imagecreate实例教程

描述
资源imagecreate($width,$height)
imagecreate()返回一个图像标识符代表了指定大小的空白图像。

我们建议使用imagecreatetruecolor()。

看个
<?php
header("Content-type: image/png");
$im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

如果您可以访问gd.h(很少在一个共享的主机),您可以修改GD_RESOLUTION并给它所需的价值。

该解决方案,我发现直接操纵的JPEG头字节。
我希望此示例代码将帮助别人,因为我花了5挖掘推测离开系统I小时,没有其他选择。

<?php
header('Content-Disposition: attachment; filename="myimg.jpg"');
header('Cache-Control: private');
$dst    = imagecreatetruecolor(300, 300); /*this creates a 300x300 pixels image*/
ob_start(); /*don't send the output to the browser since we'll need to manipulate it*/
ImageJpeg($dst);
$img = ob_get_contents();
ob_end_clean();

//byte #14 in jpeg sets the resolution type: 0=none, 1=pixels per inch, 2=pixels per cm
//bytes 15-16 sets X resolution
//bytes 17-18 sets Y resolution
$img = substr_replace($img, pack('cnn',1,300,300),13,5);

echo $img;

?>

文件在其文件类型,并返回假的负载如果失败
<?php
function imagecreatefromfile($path, $user_functions = false)
{
    $info = @getimagesize($path);
   
    if(!$info)
    {
        return false;
    }
   
    $functions = array(
        IMAGETYPE_GIF => 'imagecreatefromgif',
        IMAGETYPE_JPEG => 'imagecreatefromjpeg',
        IMAGETYPE_PNG => 'imagecreatefrompng',
        IMAGETYPE_WBMP => 'imagecreatefromwbmp',
        IMAGETYPE_XBM => 'imagecreatefromwxbm',
        );
   
    if($user_functions)
    {
        $functions[IMAGETYPE_BMP] = 'imagecreatefrombmp';
    }
   
    if(!$functions[$info[2]])
    {
        return false;
    }
   
    if(!function_exists($functions[$info[2]]))
    {
        return false;
    }
   
    return $functions[$info[2]]($path);
}
?>

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 图片下载程序

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");
  }
 }

[!--infotagslink--]

相关文章

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

    这篇文章主要介绍了使用PHP+JavaScript将HTML元素转换为图片的实例分享,文后结果的截图只能体现出替换的字体,也不能说将静态页面转为图片可以加快加载,只是这种做法比较interesting XD需要的朋友可以参考下...2016-04-19
  • C#从数据库读取图片并保存的两种方法

    这篇文章主要介绍了C#从数据库读取图片并保存的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2021-01-16
  • php抓取网站图片并保存的实现方法

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

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

    这篇文章主要介绍了Python 图片转数组,二进制互转操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-09
  • 利用JS实现点击按钮后图片自动切换的简单方法

    下面小编就为大家带来一篇利用JS实现点击按钮后图片自动切换的简单方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2016-10-25
  • jquery左右滚动焦点图banner图片鼠标经过显示上下页按钮

    jquery左右滚动焦点图banner图片鼠标经过显示上下页按钮...2013-10-13
  • js实现上传图片及时预览

    这篇文章主要为大家详细介绍了js实现上传图片及时预览的相关资料,具有一定的参考价值,感兴趣的朋友可以参考一下...2016-05-09
  • Photoshop枪战电影海报图片制作教程

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

    这篇文章主要介绍了JS创建Tag标签的方法,结合具体实例形式分析了javascript动态操作页面HTML元素实现tag标签功能的步骤与相关操作技巧,需要的朋友可以参考下...2017-06-15
  • JavaScript动态创建div属性和样式示例代码

    1.创建div元素: Javascript代码 复制代码 代码如下: <scripttypescripttype="text/javascript"> functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.innerHTML="Testcreateadiveleme...2013-10-13
  • python opencv通过4坐标剪裁图片

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

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

    这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
  • PHP swfupload图片上传的实例代码

    PHP代码如下:复制代码 代码如下:if (isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) { $upload_file = $_FILES['Filedata']; $fil...2013-10-04
  • C#中图片旋转和翻转(RotateFlipType)用法分析

    这篇文章主要介绍了C#中图片旋转和翻转(RotateFlipType)用法,实例分析了C#图片旋转及翻转Image.RotateFlip方法属性的常用设置技巧,需要的朋友可以参考下...2020-06-25
  • ps怎么制作图片阴影效果

    ps软件是现在很多人比较喜欢的,有着非常不错的使用效果,这次文章就给大家介绍下ps怎么制作图片阴影效果,还不知道制作方法的赶紧来看看。 ps图片阴影效果怎么做方法/...2017-07-06
  • OpenCV如何去除图片中的阴影的实现

    这篇文章主要介绍了OpenCV如何去除图片中的阴影的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-29
  • JavaScript 如何禁止用户保存图片

    这篇文章主要介绍了JavaScript 如何禁止用户保存图片,帮助大家完成需求,更好的理解和使用JavaScript,感兴趣的朋友可以了解下...2020-11-19
  • C#将图片和字节流互相转换并显示到页面上

    本文主要介绍用C#实现图片转换成字节流,字节流转换成图片,并根据图片路径返回图片的字节流,有需要的朋友可以参考下...2020-06-25