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;
    }