插件17:图像显示

<?php // Plug-in 17: Image Display

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
// You will need an image file called pic.jpg in this folder

PIPHP_ImageDisplay("pic.jpg", "", NULL);

// Try commenting out the above line and uncommenting one below

// PIPHP_ImageDisplay("pic.jpg", "gif",  NULL);
// PIPHP_ImageDisplay("pic.jpg", "png",  50);
// PIPHP_ImageDisplay("pic.jpg", "jpeg", 20);

function PIPHP_ImageDisplay($filename, $type, $quality)
{
   // Plug-in 17: Image Display
   //
   // This plug-in takes an image file name, loads it
   // and displays it to a browser. The image can be
   // converted on the fly to different types and quality.
   // The arguments required are:
   //
   //    $filename: Path and/or name of image to display
   //
   //    $type: Type of file to display:
   //
   //       "":     Output as current type
   //       "gif":  Output as a gif image
   //       "jpeg": Output as a jpeg image
   //       "png":  Output as a png image
   //
   //    $quality: Quality of image (0-99).
   //              Only used if $type is jpeg or png
   //
   //        0 = Lowest quality and smallest size
   //       99 = Best quality and largest size

   $contents = file_get_contents($filename);
   
   if ($type == "")
   {
      $filetype = getimagesize($filename);
      $mime     = image_type_to_mime_type($filetype[2]);
      header("Content-type: $mime");
      die($contents);
   }

   $image = imagecreatefromstring($contents);
   header("Content-type: image/$type");
   
   switch($type)
   {
      case "gif":  imagegif($image); break;
      case "jpeg": imagejpeg($image, NULL, $quality); break;
      case "png":  imagepng($image,  NULL,
                     round(9 - $quality * .09)); break;
   }
}

?>

插件说明:

插件17输入的参数包括一个图像的文件名、图像类型、显示质量。具体如下:

$filename 字符串,表示一个图像的路径和文件名。

$type 图像文件的类型(GIF\JPEG或PNG).

$quality 表示jpeg或png图像的显示质量(0表示最低质量,99表示最高质量)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值