Extract a bitmap from PostScript

时间秒杀一切 提交于 2019-12-08 06:08:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!