PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
![]() | ![]() | ![]() | ![]() | ![]() |
GetImageHeightWidth() |
This is an inbuilt function function provided by PPWIZARD.
This function can be used to automatically generate the HEIGHT and WIDTH parameters on a html "IMG" tag.
The function takes these parameters (all but the first being optional):
If you need to produce a format not generated by this function then I recommend that this format be used and parsed to separate the two values (or that 2 calls be made using "W#" and "H#"), for example:
;--- Get height and Width ----------------------- parse value GetImageHeightWidth('some.gif',,,'W,H') with @@Width ',' @@Height; ;--- Use the values to produce desired format --- @@WantedFmt = "HEIGHT=" || @@Height || " WIDTH=" || @@Width;
The scaling factor can be in these formats:
Note that scaling both sizes of an image by "50%" gives you an image a 1/4 of the size.
If an error occurs the routine aborts, otherwise a string similar to "WIDTH=10 HEIGHT=20" gets returned. If you have one of the supported image types and ppwizard fails to handle it please send it to me zipped so I can update ppwizard as required.
Note that as the image file needs to be read to determine its size this routine will slow down the preprocessing of your files. You could get smart and generate an image header file of sizes (each one #defined) so that a separate slow step generates a header file that html source includes.
Example #1 - IMG Macro |
This demonstrates how you can create an "IMG" macro which can take any number of html IMG tag parameters. It generates a HTML image tag with the height and width parameters added:
;--- We will make use of existing functionality ----------------------------- #define FILEINFO_DEFAULT_PATH ..\ ;;This plus "SRC" value indicates where "LOCAL" file is (build time), in my case its in "..\graphics" #include "FILEINFO.H" ;--- Image Macros ----------------------------------------------------------- #define IMG \ ;--- Get image & video information using rexx code -- -\ #DefineRexx '' -\ ;--- Make sure IMG file exists etc --------------- -\ <$RexxVerifyLocalInputFile FILE="{$SRC}">; -\ -\ ;--- Get Image Height & Width -------------------- -\ RxImgHw = GetImageHeightWidth(<$FILEINFO_RXVAR_FULL_LOCAL_FILE>); -\ #DefineRexx -\ -\ ;--- Generate the "IMG" tag ------------------------- -\ <IMG SRC="{$SRC}" <??RxImgHw>{$? $$PASSDSQ $$SPCPLUS}> ;--- Test macro ------------------------------------------------------------- <$IMG SRC="16x12.gif"> <$IMG ALT="a graphic" SRC="16x12.gif"> <$IMG ALT="a graphic" SRC="16x12.gif" X='Y'>
Example #2 |
This demonstrates the creation of image tables (using "styles"):
;--- Photo macro will either use passed size or work out correct size for you --- #define Photo \ #evaluate+ LocalFileName ^"..\graphics\{$Image}"^ \ #DependsOn INPUT "<$LocalFileName>" \ <TR> \ #if "{$Size=''}" <> "" \ #define+ TmpSize {$Size=''} ;;User supplied size \ #elseif \ #evaluate+ TmpSize ^GetImageHeightWidth("<$LocalFileName>")^ \ #endif \ <TD ALIGN=CENTER> \ <IMG SRC="graphics/clear1x1.gif" WIDTH=1 HEIGHT=1 VSPACE=20> \ {$Title}<BR><BR> \ <IMG SRC="graphics/{$Image}" BORDER=0 <$TmpSize> ALT="{$Title}"> \ <IMG SRC="graphics/clear1x1.gif" WIDTH=1 HEIGHT=1 VSPACE=20> \ </TR>
;--- Create table of photos -------------------------------------------- <BR><CENTER><TABLE COLS=1 BORDER=10 CELLSPACING=10> <TR> <TH ALIGN=CENTER>Pictures </TR> ;--- Include all my photos ------------------------------------------ <$Photo Image="lazy.jpg" Title="Watching TV"> <$Photo Image="carback.jpg" Title="New Car (Back Left)"> </TABLE></CENTER>
Example #3 |
This example shows how you can manipulate the format of the height and width text, this example produces "width,height":
;--- Define macro which creates 'new Image(W,H);' text ---------------------- #defineRexx '_ImageWidthCommaHeight_' ;--- Get heigth and width for image (seperated them from fixed text) ----- parse value GetImageHeightWidth("{$IMAGE}") with 'WIDTH="' iWidth '" HEIGHT="' iHeight '"' ;--- Format the information the way we need it --------------------------- iWidthHeight = iWidth || ',' || iHeight; #defineRexx #define ImageWidthCommaHeight \ #evaluate ^^ ^<$_ImageWidthCommaHeight_ {$?}>^ -\ <??iWidthHeight> ;--- Test macro ------------------------------------------------------------- JsVar = new Image(<$ImageWidthCommaHeight IMAGE="graphics\ppw_bg.jpg">);