<?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表示最高质量)。