如何在 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); ?>
.jpg)
示例 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); ?>
输出
.jpg)
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP