The SAS Output Delivery System and reporting techniques

Find external image resolution

Reply
N/A
Posts: 0

Find external image resolution

Dears

I am wondering could any of you having a way to detect the dimention sizes (resolution) of an external image file within a SAS session dynamically. I have created as import macro to load image files in JP(E)G, PNG, GIF etc. format, but the original image size is essential to keep the graph aspect ratio in SAS. Many thanks in advance.

With kind regards
SSAS
SAS Super FREQ
Posts: 8,868

Re: Find external image resolution

Posted in reply to deleted_user
Hi:
You need to figure out the HSIZE/VSIZE or XPIXEL/YPIXEL goption settings and the driver you're going to use may have an effect on these settings. This paper has some useful information: http://support.sas.com/rnd/papers/sgf07/sgf2007-gsf.pdf

The GIF driver set has a way for you to pick the resolution by using the appropriate driver name: GIF570, 570x430 pixels; GIF373, 373x280 pixels; or GIF260, 260x195 pixels, etc. Here's another useful paper:
http://support.sas.com/techsup/technote/ts674/ts674.html

However, this is not an ODS or BASE Reporting procedure question and for a question like this, Tech Support is your best bet for help, especially, since doing anything dynamically generally involves using the SAS Macro facility.

To contact Tech Support, go to http://support.sas.com and on the left-hand navigation pane, click on the link, entitled: "Submit a Problem".

cynthia
N/A
Posts: 0

Re: Find external image resolution

Posted in reply to deleted_user
Dear Cynthia

Many thanks to your timely reply and advices. The question has sent to SAS support 3-4 months ago, the reply was no method so far can detect external image size from within SAS session. That's why I am trying to have advices or tips from our fellow experts.

I might have not been given the scenario very clear here. In my case, I want to import image files (in GIF, PNG, JP(E)G BMP format, which were created from other Stat application such as S-plus, R, Sigmaplot etc., most possibly done by other people and the size is not known) into SAS, then re-load it into PDF file. So far, the macros of importing and reloading were developed and work well. The problem comes from time to time that, if external image size (in terms of Inch, cm or Pixels) not manaully give to the import macro, the final image in PDF file might be squeezed or streched too much. So far, many of the SAS DOCs were emphasized on exporting the graphs to PDF, HTML etc. as those you have mentioned to me (thanks again), but less in importing. There is one for importing external CGM file but not useful to me.

Kind regards
Ssas
Super Contributor
Posts: 394

Re: Find external image resolution

Posted in reply to deleted_user
You say "resolution," that is, pixels per inch or centimeter, but it sounds like you mean "dimensions," the number of columns and rows.

In either case, check out ImageMagick at http://www.imagemagick.org. This package includes a command called "identify" that prints the dimensions and resolution of an image along with a lot of other information. Here's a SAS program that runs identify and parses its output:

[pre]
filename id pipe 'identify myimage.jpg';
data _null_;
attrib imgname length=$12 format length=$8 dimensions length=$9;
infile id;

/*
Skip to the 2nd line. The first word in the line is the image filename.
The 2nd is the image format, in this case 'JPEG'. The third word are the
dimensions, which are displayed in the form CCCCxRRRR.
*/
input / imgname format dimensions;
columns = input(scan(dimensions, 1, 'x'), best.);
rows = input(scan(dimensions, 2, 'x'), best.);
put _all_;
run;
[/pre]

If you need the resolution use the -verbose option on identify.
ImageMagick is free, supports over 100 different image formats, and runs on just about any platform you can imagine.
Super Contributor
Posts: 358

Re: Find external image resolution

Posted in reply to deleted_user
Hi:

I remember having to do this too many years ago. There was a way to examine the code in the image to determine the height and width of the file. I'm afraid I can't remember the code that I used but I do remember that I started with some rexx code that was first developed for OS/2.

http://hobbes.nmsu.edu/cgi-bin/h-viewer?sh=1&fname=/pub/os2/dev/rexx/gif_info.zip

If you look at these modules they may point you in the right direction.
N/A
Posts: 0

Re: Find external image resolution

Posted in reply to deleted_user
Hi All

Many thanks to all of your contribution to solve my problem.

With the file "ImageMagick-6.3.7-1-Q16-windows-dll.exe" downloaded from "http://www.imagemagick.org/script/binary-releases.php#windows" and installed on my PC, the SAS program below can directly get image resolution (or size roughly in IN) as wanted.

Cheers!
Ssas


FILENAME id PIPE "IDENTIFY image-file";

DATA _NULL_;
LENGTH dimension $20 width height $8;
INFILE id LENGTH = linelen;
INPUT @ ;
varlen = linelen;
INPUT @1 lineread $varying200. varlen;
dimension=SCAN(lineread, 3, ' ');
width =SCAN(UPCASE(dimension), 1, 'X');
Height =SCAN(UPCASE(dimension), 2, 'X');
CALL SYMPUT("ImageW", TRIM(LEFT(width/72)));
CALL SYMPUT("ImageH", TRIM(LEFT(height/72)));
CALL SYMPUT("ImageD", TRIM(LEFT(dimension)));
RUN;

%PUT Image resolution: &ImageD *** Width x Height(in): &ImageW x &ImageH;
N/A
Posts: 0

Re: Find external image resolution

Posted in reply to deleted_user
Hi BelSsas,

I wonder if you can share with me the macros you used to import image files (.JPG, PNG, GIF) to SAS. I have similar needs to load external image files to SAS.

Thanks!

SAS@Time
Ask a Question
Discussion stats
  • 6 replies
  • 242 views
  • 0 likes
  • 4 in conversation