1

I need to extract a bitmap from a PostScript file (.ppf). It is compressed with RLE and encoded with ASCIIHexEncode. I will call it from PHP. I wonder if there is an elegant way to do that. I don't want to reinvent wheel, but I would like to use existing libraries. Is there a way how to call compression filters from PostScript, Ghostscript or imagick?

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Joe Bobson
  • 1,216
  • 15
  • 19

1 Answers1

3

You can write a PostScript program to run compression/decompression filters on input. So, if you have the bitmap data already extracted in a file called myfile.rle.hex, you could put this in a file (eg called decode.ps) :

/InFile (/home/ken/myfile.rle.hex) (r) file /ASCIIHexDecode filter 
/RLEDecode filter 
def
/OutFile (/home/ken/myfile.raw) (w) file def
/Data 32768 string def

{
    InFile Data readstring {
    OutFile exch writestring
    } {
    OutFile exch writestring
    exit
    } ifelse
} loop

InFile closefile
OutFile closefile

Then "gs decode.ps". There are other ways to achieve this, you could put the whole lot on the Ghostscript command line using -c, you could define the file name on the command line with -c and then run decode.ps but replacing (/home/ken/myfile.hex.rle) with the filename you defined on the command line. You can use other filters to find the data in the original PostScript.

But I can't really suggest any of these without knowing more about how you see the input and output working.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thank you for your example. Yes. That is the way I want go. I dont know postscript at all, but I will try to play little bit with ghostscript called from php. That should work. – Joe Bobson May 18 '13 at 19:49