|
Posted by anatolym on October 27, 2004, 3:36 pm
Please log in for more thread options
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
|
|
Posted by Martien Verbruggen on October 30, 2004, 9:39 pm
Please log in for more thread options
On 27 Oct 2004 14:36:59 -0700,
> 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.
You will only be successful in that if you know how the XML is built up.
If you don't know the format of the data, then you have very little
chance to decode it.
[snip XML]
I've done a bit of snooping around, and I found one XML DTD that
actually seems to have all the elements that you have in that XML. If
that DTD is the one used for this, then your image data is probably a
base 64 encoded string representing each pixel's index into the palette.
However, I'm just guessing. I'd ask the people who created the XML file
in the first place.
> I tried to use Imager module to read this in and write to a file:
I doubt very much that it will be able to take random unspecified data
you throw at it, and make sense of it for you. I suspect you'll have to
do the hard work, and try a few things, or find the documentation or
information on this from the source.
Martien
--
|
Martien Verbruggen | The world is complex; sendmail.cf reflects
| this.
|
|
|
Posted by Martien Verbruggen on December 14, 2004, 5:59 am
Please log in for more thread options in moderation. Why, they say small amounts of wine are even good
for you! It won't do me any harm if I take just one little drink..."
Well you know what is going to happen. Never forget that the human
race with technology is just like an alcoholic with a barrel of wine.
204. Revolutionaries should have as many children as they can. There
is strong scientific evidence that social attitudes are to a
significant extent inherited. No one suggests that a social attitude
is a direct outcome of a person's genetic constitution, but it appears
that personality traits tend, within the context of our society, to
make a person more likely to hold this or that social attitude.
Objections to these findings have been raised, but objections are
feeble and seem to be ideologically motivated. In any event, no one
denies that children tend on the average to hold social attitudes
similar to those of their parents. From our point of view it doesn't
matter all that much whether the attitudes
|
|
Posted by anatolym on December 14, 2004, 8:04 am
Please log in for more thread options atmosphere of the later
period. . .The move to the cities had, in short, produced a more
tractable, more socialized, more 'civilized' generation than its
predecessors."
17. (Paragraph 117) Apologists for the system are fond of citing cases
in which elections have been decided by one or two votes, but such
cases are rare.
18. (Paragraph 119) "Today, in technologically advanced lands, men
live very similar lives in spite of geographical, religious and
political differences. The daily lives of a Christian bank clerk in
Chicago, a Buddhist bank clerk in Tokyo, a Communist bank clerk in
Moscow are far more alike than the life any one of them is like that
of any single man who lived a thousand years ago. These similarities
are the result of a common technology. . ." L. Sprague de Camp, "The
Ancient Engineers," Ballentine edition, page 17.
The lives of the three bank clerks are not IDENTICAL. Ideology does
have SOME effect. But all technological societies, in ord
|
| Similar Threads | Posted | | Parsing XML data as it arrives from LWP call | January 11, 2005, 1:57 am |
| How to solve memory problems while running a script parsing huge data | July 13, 2004, 1:23 pm |
| XML::DOM parsing pb | March 9, 2006, 1:27 pm |
| XML Parsing too slow | November 19, 2005, 7:29 am |
| HTML parsing | March 21, 2005, 3:24 pm |
| CGI.pm parsing odity | May 16, 2006, 10:01 am |
| Parsing OpenOffice Spreadsheets | April 25, 2005, 7:23 pm |
| can't find xml-parsing module... | May 27, 2006, 5:30 am |
| Lemur parsing module | June 20, 2006, 10:44 pm |
| XML::Atom::Feed - parsing at all? | January 20, 2008, 5:04 pm |
|