0

I am creating a post script file and text and lines work good. I need to put jpeg and gif images on it. How do I read in the jpeg or gif file and convert it to post script data so that the image appears correctly?

I found this on the internet but when I read in my jpeg and simply convert the file to hex bytes it doesn't appear correctly.

100 200 translate
26 34 scale
26 34 8 [26 0 0 -34 0 34]
{<
ffffffffffffffffffffffffffffffffffffffffffffffffffff
ff000000000000000000000000000000000000ffffffffffffff
ff00efefefefefefefefefefefefefefefef0000ffffffffffff
...
ff00efefefefefefefefefefefefefefefefefefefefefef00ff
ff000000000000000000000000000000000000000000000000ff
ffffffffffffffffffffffffffffffffffffffffffffffffffff
>}

image

That second to last line is greater than symbol followed by curly braces.

Thank you

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138

1 Answers1

0

The example you have found declares the image data using a procedural data source and no compression. Fortunately for you, a JPEG (specifically JFIF) image can be placed into a PostScript program, and the DCTDecode filter applied in order to decode it.

So you need to use a file data source, with currentfile as the input, and apply a DCTDecode filter to the file. Then put the image data after the image operator. Note that since this is a file rather than string data source you either put the image data in as binary, or you will need to apply multiple filters to the image source, eg ASCII85Dcode.

Obviously you will also need to know the width, height and colour depth of the image data and you should use the dictionary form of the image operator instead of the multiple argument form in your example code.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thank you. My knowledge of PostScript consists basically of looking at files produced by a tool we have at work and what I have found online so unfortunately I am not familiar with what a DCTDecode filter or the ASCII85Dcode filter. I have read enough to agree that I should use the dictionary form. Can you point me to an example of what you are referring too? – user3991484 Sep 05 '16 at 01:52
  • You are going to have to learn some PostScript, there's no easy way to do this and I don't think cargo cult programming is going to help you out here, you are actually going to have to understand it. You *could* look at the viewjpeg.ps PostScript program in the Ghostscript distribution but you may struggle to follow what it does. – KenS Sep 06 '16 at 07:47