
Jeffrey Bush - 2008-10-07 00:29:02
There are a few problems that I have found how to correct.
1) On some machines the machine byte order is not the icon byte order. In all unpack statements, L should be V and S should be v to add support for these machines.
2) To support icons that are 256 pixels wide/tall, the following code needs to be added to the middle of the first loop of LoadData:
if ($icodata['Height'] == 0) $icodata['Height'] = 256;
if ($icodata['Width'] == 0) $icodata['Width'] = 256;
3) Some icons use embedded PNG files which this class does not support. To add support for this the following code needs to be added to the beginning of the second loop of LoadData:
if (substr($data, $this->formats[$i]['FileOffset'], 8) == "\x89PNG\x0D\x0A\x1A\x0A") {
$this->formats[$i]['isPNG'] = true;
$this->formats[$i]['data'] = substr($data, $this->formats[$i]['FileOffset'], $this->formats[$i]['SizeInBytes']);
$this->formats[$i]['data_length'] = $this->formats[$i]['SizeInBytes'];
continue;
}
$this->formats[$i]['isPNG'] = false;
And the following code needs to be added GetIcon after the first if statement:
if ($this->formats[$index]['isPNG']) {
if ($this->bgcolor_transparent)
return imagecreatefromstring($this->formats[$index]['data']);
$im = imagecreatetruecolor($this->formats[$index]['Width'], $this->formats[$index]['Height']);
$bgcolor = $this->AllocateColor($im, $this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]);
imagefilledrectangle($im, 0 , 0, $this->formats[$index]['Width'], $this->formats[$index]['Height'], $bgcolor);
$png = imagecreatefromstring($this->formats[$index]['data']);
imagecopy($im, $png, 0, 0, 0, 0, $this->formats[$index]['Width'], $this->formats[$index]['Height']);
imagedestroy($png);
return $im;
}