PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: GetIdPrepare()[Next]: GetInputFileNameAndLine()
\ -> Rexx -> Inbuilt PPWIZARD Functions -> 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):

  1. The name of a file (.GIF, .JPG, .PNG or .BMP)

  2. The width scaling factor (default = "100%").

  3. The height scaling factor (default = "?").

  4. The format of the returned information, one of the following:

  5. By default this function caches results so that it does not have to re-read a file if it is used multiple times. The cache is maintained across individual builds for the life of a ppwizard invokation. Pass 'Y' for this parameter if you want to bypass all cache logic.

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>        \
    ;--- Create table of photos --------------------------------------------
       <TH ALIGN=CENTER>Pictures

       ;--- Include all my photos ------------------------------------------
       <$Photo Image="lazy.jpg"     Title="Watching TV">
       <$Photo Image="carback.jpg"  Title="New Car (Back Left)">

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;
#define ImageWidthCommaHeight                             \
        #evaluate ^^ ^<$_ImageWidthCommaHeight_ {$?}>^   -\

;--- Test macro -------------------------------------------------------------
JsVar = new Image(<$ImageWidthCommaHeight IMAGE="graphics\ppw_bg.jpg">);

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: GetIdPrepare()[Next]: GetInputFileNameAndLine()

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am