Rebol Programming/load-image

From Wikibooks, open books for an open world
Jump to navigation Jump to search

USAGE:[edit | edit source]

LOAD-IMAGE image-file /update /clear 

DESCRIPTION:[edit | edit source]

Load an image through an in-memory image cache.

LOAD-IMAGE is a function value.

ARGUMENTS:[edit | edit source]

  • image-file -- Local file or remote URL (Type: file url)

REFINEMENTS:[edit | edit source]

  • /update -- Force update from source site
  • /clear -- Purge the entire cache

SOURCE CODE[edit | edit source]

load-image: func [
    "Load an image through an in-memory image cache." 
    image-file [file! url!] "Local file or remote URL" 
    /update "Force update from source site" 
    /clear "Purge the entire cache" 
    /local image image-cache
][
    image-cache: [] 
    if clear [system/words/clear image-cache recycle] 
    if any [update not image: select image-cache image-file] [
        if all [update image] [remove/part find image-cache image-file 2] 
        repend image-cache [
            image-file 
            image: either file? image-file [load image-file] [
                either update [load-thru/binary/update image-file] [load-thru/binary image-file]
            ]
        ]
    ] 
    image
]