<?php // Plug-in 16: Image Enlarge
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
// You will need a small jpeg file called icon.jpg in this folder
$image = imagecreatefromjpeg("icon.jpg");
$image1 = PIPHP_ImageResize($image, 285, 214);
imagejpeg($image1, "icon2.jpg");
$image1 = PIPHP_ImageEnlarge($image, 285, 214, 15);
imagejpeg($image1, "icon3.jpg");
echo "<img src='icon.jpg' align='left'>This is a 100 x 75 ";
echo "pixel icon. Below the icon has been enlarged to 285 x ";
echo "214 pixels using the Image Resize plug-in on the left ";
echo "and Image Enlarge on the right. The left image is ";
echo "clearly pixelated while the right one is smoother.";
echo "<br clear='left' /><img src='icon2.jpg' /> ";
echo "<img src='icon3.jpg' />";
function PIPHP_ImageEnlarge($image, $w, $h, $smoothing)
{
// Plug-in 16: Image Enlarge
//
// This plug-in takes a GD image and enlarges it to the
// required dimensions through several resamples. The
// arguments required are:
//
// $image: The image source
// $w: New width
// $h: New height
// $smoothing: The amount to smooth by (0-90):
// 0 = Minimum smoothing
// 90 = Maximum smoothing
$oldw = imagesx($image);
$oldh = imagesy($image);
$step = 3.1415927 * ((100 - $smoothing) / 100);
$max = $w / $step;
$ratio = $h / $w;
for ($j = $oldw ; $j < $max; $j += $step)
$image = PIPHP_ImageResize($image, $j * $step,
$j * $step * $ratio);
return PIPHP_ImageResize($image, $w, $h);
}
// The function below is repeated here
// just for the sake of this example as it
// is called by it.
function PIPHP_ImageResize($image, $w, $h)
{
// Plug-in 12: Image Resize
// This plug-in takes a GD image and resizes it to the
// required dimensions. The arguments are:
// $image: The image source
// $w: New width
// $h: New height
$oldw = imagesx($image);
$oldh = imagesy($image);
$temp = imagecreatetruecolor($w, $h);
imagecopyresampled($temp, $image, 0, 0, 0, 0,
$w, $h, $oldw, $oldh);
return $temp;
}
?>
插件说明:
插件16接受一个需要放大的GD图像、图像放大后的宽度和高度以及平滑程度。具体如下:
$image 需要放大的GD图像。
$w 新图像的宽度。
$h 新图像的高度。,
$smoothing 平滑程度("0"为最不平滑,"90"为最平滑)。