Skip to Content.
Sympa Menu

baslinux - Re: [BL] simple doc to png convertor

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: sindi keesan <keesan AT sdf.lonestar.org>
  • To: baslinux AT lists.ibiblio.org
  • Subject: Re: [BL] simple doc to png convertor
  • Date: Mon, 25 Apr 2005 00:47:34 +0000 (UTC)

On Sun, 24 Apr 2005, David Moberg wrote:

----- Original Message -----
From: "sindi keesan" <keesan AT sdf.lonestar.org>

I used a DOS port of wvware to extract the png from a doc file that
consists only of one embedded png, produced by a scanner.

Viewed with less, the png file starts with <89>PNG.

According to /etc/magic, this is "\x89PNG". \x89 means a byte/char of
value 89. So, 4 bytes:

1 89
2 'P'
3 'N'
4 'G'

(C char notation)

I found \x89PNG in /etc/magic, which appears to be something used by a game, but don't follow the rest of this.


The doc file has a lot of <FF) and @^ and then <89>PNG. At the end
it has more <FF> and @^ and then something about WORD.

I could probably just use a text editor to manually chop off the
beginning and end of this sort of doc file instead of wvware, but
can someone suggest a script which would delete all characters
before <89>PNG

#!/bin/sh
export POSIXLY_CORRECT=""
expr index "`cat $1`" "`echo 3PNG | tr 3 '\211'`" >/tmp/1
expr `cat /tmp/1` - 1 >/tmp/1
expr `cat $1 | wc -c` - `cat /tmp/1` >/tmp/1
tail -c `cat /tmp/1` $1
rm -f /tmp/1

I have non-busybox tail and busybox tr, wc, cat, and expr.

How did <80>PNG become 3PNG?

I downloaded this email and copied the above to a program doctopng, chmod +x'ed it, and then typed doctopng doc1.doc > doctopng.png

I get the error message:
tail: doc1.doc: invalid number of bytes

Are you using wc to count the number of bytes before PNG and then trying to remove that number of bytes from the start of the file with tail?


I'm not sure if BusyBox wc will work with this. You need write
access to /tmp/1. To run, save to (for example) pngtrim.sh and
do pngtrim.sh example.doc >output.png.



The png file ends with IEND<AE>B`<82>. The WORD file continues
with many pages of @^ (to encourage you to get a larger hard
drive?) and <FF> and then the names of the two people working at
that office repeatedly, some comments on what is in the document
that they probably added, and various mentions of Microsoft Word
9.0. So I could also just chop that off.

Do you want a script that does that, too?

One that does both would be ideal so that I will have just the PNG part.
I had no idea it would be that complicated. With pico I just search on PNG and END and delete by blocking and Ctrl-K.


<82> is presumably a hex character and perhaps a shell script would
need to refer to it differently.

Very differently for <89>. The method I used above is very ugly.

Maybe there is a simpler way?


Pico shows a file starting in a
small dark box and ending in this same box plus Spanish upside-down
question mark.
I included the IEND in case the <AE>etc. part occurred elsewhere.

I wonder if all PNG files end this way?

I will go make a png file from something else and look at it..... jpegtopnm and then pnmtopng (which takes longer)....

Yes, this file starts and ends exactly the same way as the one in the doc.
<89>PNG and IEND....<82>

Sindi




Archive powered by MHonArc 2.6.24.

Top of Page