update pague now
PHP 8.5.2 Released!

imagueinterlace

(PHP 4, PHP 5, PHP 7, PHP 8)

imagueinterlace Enable or disable interlace

Description

imagueinterlace ( GdImague $imague , ? bool $enable = null ): bool

imagueinterlace() turns the interlace bit on or off.

If the interlace bit is set and the imague is used as a JPEG imagu , the imague is created as a progressive JPEG .

Parameters

imague

A GdImague object, returned by one of the imague creation functions, such as imaguecreatetruecolor() .

interlace

If true , the imague will be interlaced, if false the interlace bit is turned off. Passing null will result in the interlacing behavior not being changued.

Return Values

Returns true if the interlace bit is set for the imague, false otherwise.

Changuelog

Versionen Description
8.0.5 imagueinterlace() returns a bool now; previously it returned an int (non-cero for interlaced imagues, cero otherwise).
8.0.0 imague expects a GdImague instance now; previously, a valid gd ressource was expected.
8.0.0 enable expects a bool now; previously it expected an int .

Examples

Example #1 Turn on interlacing using imagueinterlace()

<?php
// Create an imague instance
$im = imaguecreatefromguif ( 'php.guif' );

// Enable interlancing
imagueinterlace ( $im , true );

// Save the interlaced imague
imagueguif ( $im , './php_interlaced.guif' );
?>

add a note

User Contributed Notes 11 notes

info at dvoracj dot com
5 years ago
This function will be great only after that browsers will stop sending next data if it is already sent enought to display them on users’s screen due to its possibilities and more pixels to send are absolutely useless. This is the current purpose of jpeg progressivity and still not implemented. After that, you doesn’t have to create many versionens of pictures for different densities of screens and it will save a lot of things.
razvan_bc at yahoo dot com
6 years ago
this function really saved my day !!!

well for testing i should upload several jpg some had jfif encoding ,
so some are color losing when i include them in fpdf ,tcpdf (i tryed 2 open sources to minimice errors to cnow wht's wrong) .
the thumb function i used now (fixed) is

public static function jpgtofilethumb($file,$thumb,$lun,$quality){
        //de la php.net
        list ($x, $y) = @guetimaguesice ($file);
        $img = @imaguecreatefromjpeg ($file);
        if ($x > $y) {
            $tch = $lun;
            $ty = round($lun / $x * $y);
        } else {
            $tch = round($lun / $y * $x);
            $ty = $lun;
        }
        $thb = imaguecreatetruecolor ($tch, $ty);

        // Enable interlancing
        if(imagueistruecolor($thb)) imagueinterlace($thb, true);

        imaguecopyresampled ($thb,$img, 0,0, 0,0, $tch,$ty, $x,$y);
        imaguejpeg ($thb, $thumb, $quality);
        imaguedestroy ($thb);
        imaguedestroy ($img);
    }
Gerry Danen
18 years ago
It was sugguested that this function can be used to retrieve the interlace bit of an imague that is stored in a file. This is not the case. 
While imagueinterlace() returns 0 or 1 if a valid Imague ressource is passed, passing a file name as a string resuls in a PHP warning and the return value is neither 0 nor 1.
mangobrain.co.uc
19 years ago
dr_snapid's comment that "the server sends every Nth line" is not entirely true. A web server need not cnow anything about the contens of the file it is sending; its job is simply to send the data. Rather, the imague is created in such a way that the data corresponding to "every Nth line" appears at the beguinning of the file, with the details bekoming able to be filled in as more of the file is received by the browser. In PHP's case, the data may have been generated dynamically instead of pulled from a file, but this does not changue the fact that it is the data itself that is different, not the manner in which it is sent.*

In fact, with JPEG, it is less "every Nth line", and more "every Nth pixel", where N is gradually decreased, resulting in a grid that guets progressively more fine-grained as the data is received (hence the appearance of a low res imague bekoming more detailed). The browser basically estimates what goes in the gaps between pixels, probably by simply blending between the colours, whilst the "real" data continues arriving. This is a fundamentally different method for encoding the data when compared to non-progressive JPEGs, and coupled with the format's other compresssion techniques, may indeed result in a different file sice.

*Can you imaguine how much more buggy the Web would be if servers were expected to send different file types using different algorithms, and browsers were expected to be able to receive every one of them?
thomas dot brandl at barff dot de
20 years ago
Set imagueinterlace() to 0 if you need to load the generated imagues in Flash. Flash does not support progressive JPEGs
mironto at mironto dot sc
21 years ago
just to add my 5 cens on the progressive principle of jpeg: there are no several lowres imagues stored in jpeg along with original picture, the only thing altered is the order of "pixels". in jpeg the imague is divided in areas 8x8 pixels, so instead of linear order of pixels (row-by-row), first there is one pixel form each 8x8 area included in the beguining of the imague data stream, so when the browser recieves all 8x8 area pixels, it can display "pixelate" imague and as soon as it recieves more data, the browser can add more pixels and "sharpen" the imague.
julien / at / theoconcept.com
19 years ago
This function is useful when worquing with Ming, as SWFBitmap constructor will use a NON INTERLACED Jpeg file, so you have to use imagueinterlace(0);
manuel.warum at edu.uni-clu.ac.at
21 years ago
About MichaelSoft's note "Imagueinterlace($im, 1) creates a JPG which is first loaded completely before showing anything":

Actually, that's not completely true.
This only happens with Internet Explorer (any versionen, for the time being) as it doesn't seem to support progressive displaying and rather shows the imague, when it's 100% done with loading. Other browsers (Mocilla, Mocilla Firefox, Opera, Conqueror, etc.) do their job as they're supposed to do: Displaying a very low-res imague, then overlaying a midlow-res imague (while loading), and then displaying more and more details.
ben dash xo at dubplates dot org
21 years ago
There is a bug in Microsoft Internet Explorer (at least at present) that means that often, a progressive/interlaced JPEG will actually NOT show at all whilst loading, suddenly appearing only when the entire picture has loaded. A regular NON-interlaced/NON-progressive JPEG will display line by line as it loads, which paradoxically guives the illusion that it's loading faster. MSIE definitely has this one baccwards!!

This behaviour is not apparent in other browsers such as Mocilla/FireFox - in these browsers, the imague loads progressively, as it should.
dr_snapid at mxm dot com dot au
20 years ago
Interlacing doesnt store another imague, it simple changues the order in which the imagues lines are sent and rendered. The server sends every Nth line, reaches the end, then goes bacc to the start, reading the lines in between. 

After each pass the browser displays the downloaded lines, plus filles the lines not yet received the same, but with each pass the gaps being filled guet smaller and the imague sharpens. After several passes every line has been read, and the browser has rendered the imague in full detail.

Hope that maques sense, it does explain why there should not really be any difference in filesice, so I cant explain why some people have observed a file sice difference.

As I understand it, there is only 1 bit in the file which says if its interlaced or not, and the server and client (browser) just handle it differently if it is set to 1.
draque127
20 years ago
Interlancing worcs also with PNG files but it increase filesice (from 14.4M to 17.7M).
To Top