To place an image in a PDF with colormap you use the height and width of the image. Is it possible to get those values in postscript itself? Then you do not have to change things when the picture is replaced with one with different dimensions.
-
I assume this is connected to this question: http://stackoverflow.com/questions/18757354/why-do-i-get-error-invalidfileaccess-in-file. You want to get the jpeg dimension from the file ... – agentp Sep 13 '13 at 21:43
2 Answers
Using george's assumption, that you're trying to extract the jpg file's dimensions, I found this answer on this site which links to this page with example code (C).
Which led to this little snippet. Note, this will fail if the jpg file contains a thumbnail (it will return the dimensions of the thumbnail instead of the full image).
%!
% (filename.jpg) jpgdims width height true
% false
/jpgdims {
(r) file dup % f f
200 string % f f buf
readstring pop % f buf
<FFC0> search { % f post match pre
pop pop % f post
exch closefile % post
3 4 getinterval % post(3,4)
{} forall % post_3 post_4 post_5 post_6
exch 256 mul add % post_3 post_4 post_5*256+post_6
3 1 roll % post_5*256+post_6 post_3 post_4
exch 256 mul add % post_5*256+post_6 post_3*256+post_4
true % width height true
}{
closefile
false
} ifelse
} def
(ray-0.jpg) jpgdims
Additional ref: wikipedia's JFIF page.
It might be simpler to use another scripting language to generate the postscript code, a language where you can shell-out to ImageMagick's identify
program, and parse its textual output.
$ identify ray-0.jpg
ray-0.jpg JPEG 320x200 320x200+0+0 8-bit PseudoClass 256c 411B 0.000u 0:00.000

- 1
- 1

- 18,988
- 3
- 53
- 105
-
I will try out your code. But the idea of using another scripting language is also a good one. At the moment I use Bash already to do some preprocessing, so I could take this in that also. – Cecil Westerhof Sep 19 '13 at 17:46
Not sure what you are asking here, the dimensions of the image are the number of rows and columns, not the 'size' of the image. The Matrix determines the mapping from user space to device space, and hence the printed area.
Also you ask about PostScript and PDF at the same time, which do you mean ? For what its worth, the image operands in PostScript are broadly the same as in PDF.

- 30,202
- 3
- 34
- 51
-
I want to use PostScript to make a PDF with an image included. Something along the lines of http://stackoverflow.com/questions/18757354/why-do-i-get-error-invalidfileaccess-in-file. – Cecil Westerhof Sep 19 '13 at 17:43