Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to add an image in postscript

I am trying to write a document in postscript.

Thus far I've been able to write simple text, and work with lines and shapes.

I'm now trying to add some images to the document. After searching on-line I can't seem to find any clear way to do this.

the snip it below is a hello world:

%!PS
/Times               
20 selectfont         
20 800 moveto         
(Hello World!) show
showpage 

All I want to do is simply insert an image (eg PNG, JPG, GIF) by specifying the x and y, co-ordinates.

Any help would be much appreciated.

like image 316
Darknight Avatar asked Feb 11 '11 11:02

Darknight


2 Answers

There is a simple method and Postscript does support the jpeg format. If you are using ghostscript you may have to use the -dNOSAFER option to open files. Here is an example:

gsave
 360 72 translate     % set lower left of image at (360, 72)
  175 47 scale         % size of rendered image is 175 points by 47 points
  500                   % number of columns per row
  133                    % number of rows
  8                    % bits per color channel (1, 2, 4, or 8)
  [500 0 0 -133 0 133]       % transform array... maps unit square to pixel
  (myJPEG500x133.jpg) (r) file /DCTDecode filter % opens the file and filters the image data
  false                 % pull channels from separate sources
  3                    % 3 color channels (RGB)
  colorimage
grestore
like image 117
Hath995 Avatar answered Nov 18 '22 01:11

Hath995


Use a program like convert and then remove any extra code it generated.

like image 42
lhf Avatar answered Nov 18 '22 02:11

lhf