refhd2.gif - 11Kb

ref2sub1.gif - 10Kb
To simply load an image onto the canvas you can use “loadimage <filename>” where <filename> is the full pathname of the image file. Compo will then load an image if it can recognise the filetype and understand the image. If you follow this command with “select last” the image is selected and can be manipulated by script commands. Note that DrawFile and ArtWorks files will be loaded as vector files by default and won’t be converted to bitmaps upon import. (Translating vector images into bitmaps is covered on another reference page.)

The command “fileinfo <filename>” will obtain and set the values of the following variables;

.fileinfo.length The file’s length
.fileinfo.there 1 if the file exists, else 0
.fileinfo.filetype The file’s type. (e.g. &AFF for a DrawFile)

You can then use these to discover details of a file (and whether it exists!) before deciding to make use of it.

Both individual image files and directories of images may be scanned and loaded using a dragbox. For example, to load a JPEG file you can use

 dragload file_c85 "Drop JPEG here" to filename$
until filename$ <> ""

The main command used here is “dragload”. This generates a dragbox on screen that act as as a target window. The “file_c85” here is the name of the sprite to display on the dragbox. Since this is the name of the icon used by the filer to indicate a JPEG the script shown above displays the icon for a JPEG in the dragbox. If you drag and drop a file onto the box its full path name is put into the chosen variable, “filename$”. Note that the loading process will actually accept any form of image file that Compo can display. Hence if it matters what filetype you wish to import you will need to test this with a ‘fileinfo’ after the filename has been obtained. If you click on the dragbox’s ‘close’ icon without giving it a file a null string will be returned instead of a filename.

You can use the above to obtain the name of any file that Compo can accept so JPEG is just used above as an example. In some cases you may wish to load a number of files, or search for a specific file. CompoScript allows you to ‘scan’ a directory for these purposes. To tell a composcript the name of a directory to scan for image files you can use

 dragload directory "Drop dir. here" to indir$
until indir$ <> ""

This script causes Compo to display a dragbox onto which you can drag and drop a directory onto. (In this case ‘directory’ is simply the name of the icon the filer uses to indicate a directory.) Once this is done the string “indir$” is given the pathname of the directory. You can then scan the directory for image files. The following script is an example of how this may be done.

 scandirectory indir$ to found$
 if found$ <> "" then
  proc process_image
until found$ = ""

The script works through the files in the directory. Each time it finds a recognisable image file it returns the file’s pathname in the variable “found$” and calls a procedure (called “process_image” in this example) which can then load the file using “loadimage found$” before processing it as you wish. Files in the scanned directory which are not images are ignored and the process ends when the scan runs out of fresh files and the value given to “found$” is then null. If you wish you can test each of the names found and only process those which you are interested in, or end the scanning once a specific file is found.

During the directory scanning process a number of useful variable are given values relating to the most recently found image file These are

.directoryscan.leafname The file’s leafname
.directoryscan.filetype The filetype
.directoryscan.length The file’s length
.directoryscan.there 1 if the file exists, else 0

You can use these values to help decide what to do with each file in turn – for example, you could choose to only load GIFs, or files with a specific name.

prevpage.gif - 1296 bytes homecc2.gif - 8Kb nextpage.gif - 1271 bytes

Content and pages maintained by: Jim Lesurf
using HTMLEdit, Compo, and TechWriter.