LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Postscript - how to insert an image? (https://www.linuxquestions.org/questions/programming-9/postscript-how-to-insert-an-image-568587/)

BrianK 07-11-2007 09:17 PM

Postscript - how to insert an image?
 
Has anyone ever done any postscript programming? I've got a nice postscript template that I modify for on-the-fly creation of .ps files (to send to the printer, and convert to pdf). I'm having a hard time inserting an image. I glanced through the 900 page doc on the postscript format but it's a bit... verbose. Hard to get to the meat of how to actually do it rather than the theory behind it.

Has anyone inserted an image into a postscript file?

wjevans_7d1@yahoo.co 07-11-2007 09:34 PM

On my shelf is a book I've used so much it's beginning to fall apart. It's PostScript Language Reference Manual from Adobe Systems Incorporated. Some people call it the Red Book.

It discusses inserting images. I haven't actually done that, but I've read it and understand it. It's not too heavy on theory (whatever "theory" means in PostScript); it's pretty straightforward.

You can get this book used on Amazon.

Hope this helps.

wjevans_7d1@yahoo.co 07-12-2007 07:08 AM

Ok, you got me interested.

I went to the Red Book and fleshed out their partial example. Run program gs against this and see what you get.

Code:

%!PS-Adobe

% location on page, in points

/lowerleftx    72 def
/lowerlefty    144 def

% size on page, in points

/destwidth    132 def
/destheight    66 def

% size of original image, in pixels

/sourcewidth    32 def
/sourceheight  16 def

% greyscale; two hex digits per pixel, with 00 being black and FF white

/bitspersample  8 def

% string to hold each row

/picstr sourcewidth string def

gsave

lowerleftx lowerlefty translate
destwidth destheight scale

sourcewidth sourceheight bitspersample    % dimensions of source image
[ sourcewidth
  0
  0
  sourceheight neg
  0
  sourceheight
]                                          % coordinate transformation matrix
{ currentfile picstr readhexstring pop }  % getting the data
image

0000000000000000000000000000000000000000000000000000000000000000
00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF0000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFF00
00FF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
00FF00000000000000000000000000000000000000000000000000000000FF00
00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
0000000000000000000000000000000000000000000000000000000000000000

grestore

showpage

Hope this helps.

BrianK 07-12-2007 06:47 PM

Quote:

Originally Posted by wjevans_7d1@yahoo.co
Ok, you got me interested.

I went to the Red Book and fleshed out their partial example. Run program gs against this and see what you get.....

interesting.... that does help... looks like you just convert each pixel to hex & splat it out in the file.

an excellent starting point. Thanks!


All times are GMT -5. The time now is 08:38 AM.