The imageinterlace() function is an inbuilt function in PHP which is used to enable or disable interlace in an image. Interlacing (also known as interleaving) 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. One difference between interlaced and non-interlaced images on a website is that the former one is loaded in a low-quality version first and then it’s quality keeps improving as the website loads whereas a non-interlaced image is loaded in a fixed quality line by line from top to bottom when the website loads.
Syntax:
int imageinterlace( resource $image, int $interlace )
Parameters: This function accepts two parameters as mentioned above and described below:
- $image: It specifies the image to be interlaced.
- $interlace: It specifies whether to enable or disable interlacing.
Return Value: This function returns 1 if the interlace bit is set for the image, otherwise 0.
Below examples illustrate the imageinterlace() function in PHP:
Program 1: In this example we will enable interlacing.
<?php // Create an image from URL $im = imagecreatefrompng( // Enable interlacing imageinterlace( $im , 1); // View the output header( 'Content-type: image/jpeg' ); imagejpeg( $im ); imagedestroy( $im ); ?> |
Output:
Program 2: In this example we will disable interlacing.
<?php // Create an image from URL $im = imagecreatefrompng( // Disable interlacing imageinterlace( $im , 0); // View the output header( 'Content-type: image/jpeg' ); imagejpeg( $im ); imagedestroy( $im ); ?> |
Output:
Reference: https://www.php.net/manual/en/function.imageinterlace.php