问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/16622427/extract-a-bitmap-from-postscript