How to enable or disable interlace using imageinterlace() function in PHP?

imageinterlace() is an inbuilt PHP function that is used to enable or disable interlace in an image. It is a method of encoding a bitmap image such that a person who has partially received it sees a degraded copy of the entire image.

Interlacing an image lets users see portions of it as it loads, and it takes different forms depending on the image type. The non-interlaced JPEGs appear line-by-line. To enable interlacing on picture, we can simply call this function with the second parameter set to 1, or set to 0 (zero) to disable it.

Syntax

int imageinterlace(resource $image, int$interlace)

Parameters

imageinterlace() takes two parameters: $image and$interlace.

• $image − Specifies the image to be interlaced. •$interlace − Specifies whether to enable or disable interlacing.

Return Values

imageinterlace() returns 1 if the interlace bit is set for the image, else it returns 0.

Example 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
imagejpeg($img); imagedestroy($img);
?>

Example 2

In this example, we have disabled interlacing.

<?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
imagejpeg($img); imagedestroy($img);
?>