private function fixInterlacedPNG($file)
    {
        if (isset($this->interlacedPNGs[$file])) {
            return $this->interlacedPNGs[$file];
        }

        $handle = fopen($file, "r");

        if (!$handle) {
            $this->Error("Cannot open ".$file);
        }

        $contents = fread($handle, 32);
        fclose($handle);

        if (ord($contents[28]) != 0) {
            $im = imagecreatefrompng($file);

            if (!$im) {
                $this->Error("Cannot create image from ".$file);
            }

            imageinterlace($im, false);
            imagealphablending($im, true);
            imagesavealpha($im, true);

            $tempname = tempnam(sys_get_temp_dir(), 'FOO');

            $ret = imagepng($im, $tempname);

            imagedestroy($im);

            if (!$ret) {
                $this->Error("Could not save a non-interlaced version of ".$file);
            }

            $this->interlacedPNGs[$file] = $tempname;
            $this->toUnlink[] = $tempname;

            return $tempname;
        }

        $this->interlacedPNGs[$file] = $file;

        return $file;
    }
private function fixInterlacedPNG($file)
    {
        if (isset($this->interlacedPNGs[$file])) {
            return $this->interlacedPNGs[$file];
        }

        $handle = fopen($file, "r");

        if (!$handle) {
            $this->Error("Cannot open ".$file);
        }

        $contents = fread($handle, 32);
        fclose($handle);

        if (ord($contents[28]) != 0) {
            $im = imagecreatefrompng($file);

            if (!$im) {
                $this->Error("Cannot create image from ".$file);
            }

            imageinterlace($im, false);
            imagealphablending($im, true);
            imagesavealpha($im, true);

            $tempname = tempnam(sys_get_temp_dir(), 'FOO');

            $ret = imagepng($im, $tempname);

            imagedestroy($im);

            if (!$ret) {
                $this->Error("Could not save a non-interlaced version of ".$file);
            }

            $this->interlacedPNGs[$file] = $tempname;
            $this->toUnlink[] = $tempname;

            return $tempname;
        }

        $this->interlacedPNGs[$file] = $file;

        return $file;
    }
private function fixInterlacedPNG ( $ file ) { if ( isset ( $ this -> interlacedPNGs [ $ file ] ) ) { return $ this -> interlacedPNGs [ $ file ] ; } $ handle = fopen ( $ file , "r" ) ; if ( ! $ handle ) { $ this -> Error ( "Cannot open " . $ file ) ; } $ contents = fread ( $ handle , 32 ) ; fclose ( $ handle ) ; if ( ord ( $ contents [ 28 ] ) != 0 ) { $ im = imagecreatefrompng ( $ file ) ; if ( ! $ im ) { $ this -> Error ( "Cannot create image from " . $ file ) ; } imageinterlace ( $ im , false ) ; imagealphablending ( $ im , true ) ; imagesavealpha ( $ im , true ) ; $ tempname = tempnam ( sys_get_temp_dir ( ) , 'FOO' ) ; $ ret = imagepng ( $ im , $ tempname ) ; imagedestroy ( $ im ) ; if ( ! $ ret ) { $ this -> Error ( "Could not save a non-interlaced version of " . $ file ) ; } $ this -> interlacedPNGs [ $ file ] = $ tempname ; $ this -> toUnlink [ ] = $ tempname ; return $ tempname ; } $ this -> interlacedPNGs [ $ file ] = $ file ; return $ file ; }
Check if PNGs passed are interlaced and make a temporary de-interlaced
version if they are.

De-interlaced versions are stored in the system temp directory and are
unlinked when the class is destructed.

@param string $file Filename of the PNG file to be checked
@return string Filename of a non-interlaced PNG
Check if PNGs passed are interlaced and make a temporary de - interlaced version if they are .