如何使用 PHP 中的 imageinterlace() 函数启用或禁用隔行扫描?

phpserver side programmingprogramming

imageinterlace() 是一个内置的 PHP 函数,用于启用或禁用图像中的隔行扫描。它是一种对位图图像进行编码的方法,这样部分接收该图像的人就会看到整个图像的降级副本。

隔行扫描图像可让用户在加载时看到图像的某些部分,并且根据图像类型采用不同的形式。非隔行扫描 JPEG 逐行显示。要在图片上启用隔行扫描,我们只需调用此函数并将第二个参数设置为 1,或设置为 0(零)以禁用它。

语法

int imageinterlace(resource $image, int $interlace)

参数

imageinterlace() 接受两个参数:$image$interlace

  • $image − 指定要隔行扫描的图像。

  • $interlace −指定是否启用或禁用隔行扫描。

返回值

imageinterlace() 如果为图像设置了隔行扫描位,则返回 1,否则返回 0。

示例 1

<?php
   //使用 imagecreatefromjpeg() 函数加载图像
   $img = imagecreatefromjpeg('C:\xampp\htdocs\test\30.jpg');
   // 使用一个函数启用隔行扫描
   imageinterlace($img, 1);

   // 查看输出图像
   header('Content-type: image/jpeg');
   imagejpeg($img);
   imagedestroy($img);
?>


示例 2

在此示例中,我们已禁用隔行扫描。

<?php
   // 使用 imagecreatefromjpeg() 函数加载图像
   $img = imagecreatefromjpeg('C:\xampp\htdocs\test\30.jpg');

   // 使用零禁用隔行扫描
   imageinterlace($img, 0);

   // 查看输出图像
   header('Content-type: image/jpeg');
   imagejpeg($img);
   imagedestroy($img);
?>

输出


相关文章