获取图像的高度和宽度

时间:2013-09-12 15:26:18

标签: postscript

要使用colormap将图像放置在PDF中,请使用图像的高度和宽度。是否有可能在postscript中获取这些值?然后,当图片被替换为具有不同尺寸的图片时,您不必更改内容。

2 个答案:

答案 0 :(得分:1)

使用乔治的假设,您尝试提取jpg文件的维度,我在此网站上找到this answer链接到this page with example code (C)

这导致了这个小片段。请注意,如果jpg文件包含缩略图(它将返回缩略图的尺寸而不是完整图像),则会失败。

%!

% (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

补充参考: wikipedia's JFIF page

使用另一种脚本语言来生成postscript代码可能更简单,这种语言可以向ImageMagick的identify程序进行外壳处理,并解析其文本输出。

$ identify ray-0.jpg
ray-0.jpg JPEG 320x200 320x200+0+0 8-bit PseudoClass 256c 411B 0.000u 0:00.000

答案 1 :(得分:0)

不确定您在这里问的是,图像的尺寸是行数和列数,而不是图像的“尺寸”。 Matrix确定从用户空间到设备空间的映射,从而确定打印区域的映射。

你也同时询问PostScript和PDF,你的意思是?值得一提的是,PostScript中的图像操作数大致与PDF格式相同。

相关问题