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


imageinterlace() 是一个内置的 PHP 函数,用于启用或禁用图像的隔行扫描。它是一种编码位图图像的方法,这样即使用户只接收了部分图像,也能看到整个图像的降级副本。

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

语法

int imageinterlace(resource $image, int $interlace)

参数

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

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

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

返回值

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

示例 1

<?php
   //load an image by using imagecreatefromjpeg() function
   $img = imagecreatefromjpeg('C:\xampp\htdocs\test\30.jpg');
   // Enable interlacing by using one
   imageinterlace($img, 1);

   // View the output image
   header('Content-type: image/jpeg');
   imagejpeg($img);
   imagedestroy($img);
?>


示例 2

在这个例子中,我们禁用了隔行扫描。

<?php
   //load an image by using imagecreatefromjpeg() function
   $img = imagecreatefromjpeg('C:\xampp\htdocs\test\30.jpg');

   // Disable interlacing by using zero
   imageinterlace($img, 0);

   // View the output image
   header('Content-type: image/jpeg');
   imagejpeg($img);
   imagedestroy($img);
?>

输出

更新于: 2021-08-09

434 次查看

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告

© . All rights reserved.