A
anatolym
Hello All,
I have a problem here and I tried a few things, but non worked.
Any help would be greatly appreciated!
I'm parsing an XML file, trying to get the image part out and save
it as an image file. File format (gif, png, jpeg, bmp) is unknown.
The following is a fragment of the XML:
<picture width="2550" height="675" baseline="674">
<pict-header>
<width>170</width>
<height>45</height>
<bits-per-pixel>8</bits-per-pixel>
<palette>
<palette-entry>#000000</palette-entry>
<palette-entry>#010101</palette-entry>
<palette-entry>#020202</palette-entry>
<palette-entry>#030303</palette-entry>
<palette-entry>#040404</palette-entry>
<palette-entry>#050505</palette-entry>
<palette-entry>#0d0d0d</palette-entry>
-- snip: lots of palette entries here --
<palette-entry>#f5f5f5</palette-entry>
<palette-entry>#f6f6f6</palette-entry>
<palette-entry>#fdfdfd</palette-entry>
<palette-entry>#fefefe</palette-entry>
<palette-entry>#ffffff</palette-entry>
</palette>
</pict-header>
<pict-data>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////8AAP////8AAAD/
/wAAAP8AAAD//wAA/wD/AAAA//8AAAD/////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////AAD///8A////AP//AP///wD/
/wD//wAAAP8A/////wD/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-- snip: more picture data ---
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////AAD/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////wAA
</pict-data>
</picture>
I tried to use Imager module to read this in and write to a file:
$type = "jpeg"; # gif, png, bmp, etc.
$filename = "fig_$iname.$type";
use Imager;
$img = Imager->new(xsize=>$pHw, ysize=>$pHh, bits=>$pBits,
type=>'paletted');
my @colors;
while($pPlt =~ m|<palette-entry>(#[\dabcdf]+)</palette-entry>|ig) {
push @colors, Imager::Color->new($1);
}
$img->addcolors(colors=>\@colors);
$img->read(data=>$pData, type=>$type) or die "Cannot read: ",
$img->errstr;
$img->write(file=>"$dir/$filename", type=>$type) or die "Cannot
write:", img->errstr;
I tryed all of the above types, but it bombs out with "Cannot read:"
every time.
Is it possible at all to parse this kind of data into a file?
If possible - what am I doing wrong?
Thanks a lot for your help!
AnatolyM
I have a problem here and I tried a few things, but non worked.
Any help would be greatly appreciated!
I'm parsing an XML file, trying to get the image part out and save
it as an image file. File format (gif, png, jpeg, bmp) is unknown.
The following is a fragment of the XML:
<picture width="2550" height="675" baseline="674">
<pict-header>
<width>170</width>
<height>45</height>
<bits-per-pixel>8</bits-per-pixel>
<palette>
<palette-entry>#000000</palette-entry>
<palette-entry>#010101</palette-entry>
<palette-entry>#020202</palette-entry>
<palette-entry>#030303</palette-entry>
<palette-entry>#040404</palette-entry>
<palette-entry>#050505</palette-entry>
<palette-entry>#0d0d0d</palette-entry>
-- snip: lots of palette entries here --
<palette-entry>#f5f5f5</palette-entry>
<palette-entry>#f6f6f6</palette-entry>
<palette-entry>#fdfdfd</palette-entry>
<palette-entry>#fefefe</palette-entry>
<palette-entry>#ffffff</palette-entry>
</palette>
</pict-header>
<pict-data>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////8AAP////8AAAD/
/wAAAP8AAAD//wAA/wD/AAAA//8AAAD/////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////AAD///8A////AP//AP///wD/
/wD//wAAAP8A/////wD/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-- snip: more picture data ---
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////AAD/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////wAA
</pict-data>
</picture>
I tried to use Imager module to read this in and write to a file:
$type = "jpeg"; # gif, png, bmp, etc.
$filename = "fig_$iname.$type";
use Imager;
$img = Imager->new(xsize=>$pHw, ysize=>$pHh, bits=>$pBits,
type=>'paletted');
my @colors;
while($pPlt =~ m|<palette-entry>(#[\dabcdf]+)</palette-entry>|ig) {
push @colors, Imager::Color->new($1);
}
$img->addcolors(colors=>\@colors);
$img->read(data=>$pData, type=>$type) or die "Cannot read: ",
$img->errstr;
$img->write(file=>"$dir/$filename", type=>$type) or die "Cannot
write:", img->errstr;
I tryed all of the above types, but it bombs out with "Cannot read:"
every time.
Is it possible at all to parse this kind of data into a file?
If possible - what am I doing wrong?
Thanks a lot for your help!
AnatolyM