1

I'm new to PostScript and I've been tasked to create a postscript file which is supposed to show a small image. The thing is that I can't rely on the run operator, as one of the premisses is that the file is kinda "self-contained".

I've seen quite a few solutions online but they were either incomplete or failed for me. Google's highest listed one was made by "loser droog" (found under following link). To test I redid everything again but failed at the point where he called "head spacewar.asc" and my output and his resembled the first view characters but later on they were completely different.

Now I am wondering how I can embed a .jpg/.jpeg file in my PostScripts sourcecode and display it afterwards.

With kind regards.

  • If you're looking at the output from `head` on a ppm or pgm file, you want the binary offset of just after the `\n`. Then in the postscript, it creates a buffer of that size and calls `readstring` to fill that buffer and discard the image header. .. But if you're embedding the data, you can just trim the header from the data manually. – luser droog Mar 16 '18 at 01:17

2 Answers2

1

Take Ghostscript; use the viewjpeg.ps program to read the original JPEG, and use the ps2write device to create a PostScript file from it. You can also (with some effort) read the PostScript program resulting from that, which might give you some insight into one possible approach to the problem.

The upcoming release (9.23) should preserve the JPEG data unchanged, though I haven't actually tried that. Earlier versions will decompress and recompress the data, you don't want to do that.

To be honest, as I said to someone else earlier this week, if you're going to work in PostScript you need to understand the language. Images and inline image data are moderately complicated. You should get whoever is tasking you with this to send you for some training.

Also, rather than Google for canned answers, try the printed reference works and write your own. The Blue Book (PostScript language tutorial and cookbook), Green Book (PostScript Language program design) and Red Book (PostScript Language Reference Manual) are all available online.

KenS
  • 30,202
  • 3
  • 34
  • 51
0

Thanky you for the answers. I found a workaround for my case as I had a simple black-white-grey picture to insert.

I had converted it to binary and used image to draw it which worked out quite nicely after using this guide.