插件16:放大图像

<?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"为最平滑)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值