BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
6 REPLIES 6
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
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
Tim_SAS
Barite | Level 11
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.
OS2Rules
Obsidian | Level 7
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.
deleted_user
Not applicable
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;
deleted_user
Not applicable
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 860 views
  • 0 likes
  • 4 in conversation