插件18:图像转换

<?php // Plug-in 18: Image Convert

// 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 photo.jpg in this folder

PIPHP_ImageConvert("photo.jpg", "photo4.png", "png", 0);

echo "A 42Kb jpeg converted to another jpeg of 8Kb (20% of ";
echo "original) at a quality setting of 25...<br />";
echo "<img src='photo.jpg' align='left'> <img src='photo4.png'>";

function PIPHP_ImageConvert($fromfile, $tofile, $type, $quality)
{
   // Plug-in 18: Image Convert
   //
   // This plug-in takes an image file name, then loads,
   // converts and saves it as a new file. The Arguments
   // required are:
   //
   //    $fromfile: Path and/or name of image to convert from
   //    $tofile:   Path and/or name of image to convert to
   //
   //    $type: Type of file to convert to:
   //
   //       "gif":  Convert to a gif image
   //       "jpeg": Convert to a jpeg image
   //       "png":  Convert to 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($fromfile);
   $image    = imagecreatefromstring($contents);

   switch($type)
   {
      case "gif":  imagegif($image,  $tofile); break;
      case "jpeg": imagejpeg($image, $tofile, $quality); break;
      case "png":  imagepng($image,  $tofile,
                     round(9 - $quality * .09)); break;
   }
}

?>

插件说明:

插件18需要输入一个图像文件名、转换后要保存的文件名以及图像质量。具体如下:

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

$tofile 字符串,表示新图像保存的路径和文件名。

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

$quality 表示JPEG或PNG图像的质量(0表示最低质量,99表示最高质量)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值