models

Class coldThumbs

lucee.Component
    extended by models.coldThumbs

ColdThumbs main component ColdThumbs is a ColdFusion component to dynamically resize and cache images.

Class Attributes:
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
  • author : Gary Stanton
  •  
    Property Summary
    type property default serializable required
    array AllowedExtensions
          AllowedExtensions.

    • access = public
    • returntype = any
    true false
    array AllowedMimeTypes
          Supported mime types.

    • access = public
    • returntype = any
    true false
    string cacheFolder
          Filesystem location of the folder in which to store cached images.

    • access = public
    • returntype = any
    true false
    string cacheURL
          The URL of the cached folder.

    • access = public
    • returntype = any
    cached true false
    cfconcurrent.ExecutorService ExecutorService
          An instance of CFConcurrent.

    • access = public
    • returntype = any
    true false
    string imageMagickLocation
          Set the location of an ImageMagick binary to use this over native Java image resizing.

    • access = public
    • returntype = any
    true false
    string interpolation
          Interpolation to use when resizing images.

    • access = public
    • returntype = any
    mitchell true false
    boolean keepFilenames
          Keep filenames.

    • access = public
    • returntype = any
    true true false
    numeric maxHeight
          The maximum height an image may be output.

    • access = public
    • returntype = any
    5000 true false
    numeric maxThreads
          Maximum number of threads to spawn.

    • access = public
    • returntype = any
    2 true false
    numeric maxWidth
          The maximum width an image may be output.

    • access = public
    • returntype = any
    5000 true false
    struct queuedThreads
          Array to hold calls queued for processing.

    • access = public
    • returntype = any
    true false
    struct runningThreads
          Struct to hold information about resizing threads.

    • access = public
    • returntype = any
    true false
    boolean useThreading
          Spawn new threads to resize images.

    • access = public
    • returntype = any
    true true false
    Constructor Summary
    init()
          Constructor.
    Method Summary
    boolean checkCachedImageExists(string filename)
         Checks the cache folder to see if a given file exists.
    string checkCacheFolder()
         Create the cache folder if it doesn't exist.
    string generateCachedFilename(struct fileInfo, numeric width, numeric height, [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string extension=''])
         Generate a cached file name from image file info.
    string getAllowedExtensions()
    string getAllowedMimeTypes()
    any getCacheFolder()
         Override default getCacheFolder to run through normalise function.
    string getCacheURL()
    string getExecutorService()
    any getImageFileInfo(string src, [string authenticationString=''])
         Get a struct of file info.
    string getImageMagickLocation()
    string getInterpolation()
    string getKeepFilenames()
    private struct getLocalFileInfo(string path)
         Get a struct of file info from a local path.
    string getMaxHeight()
    string getMaxThreads()
    string getMaxWidth()
    any getMemento()
         getMemento.
    string getQueuedThreads()
    private struct getRemoteFileInfo(string url, [string authenticationString=''])
         Get a struct of file info from a remote URL.
    string getRunningThreads()
    any getThumbnail(string src, [string authenticationString=''], [numeric width='0'], [numeric height='0'], [string imageType=''], [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string backgroundColor], [boolean regenerate='false'], [boolean useThreading='[runtime expression]'])
         Retrieve a thumbnail from the cache or generate a new one from source.
    string getUseThreading()
    private boolean isRequestInThread()
         Check to see if the current request is in a thread, as we can't have nested threads.
    private any normalisePath(string path)
         Normalise the file path by replacing back slashes and removing duplicates.
    private any processQueue()
         Process images stored in the thread queue.
    private any resizeImage(struct theImage, string cachedFilename, struct fileInfo, numeric width, numeric height, [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string backgroundColor], [string authenticationString=''])
         Resize the image.
    private any resizeImageInThread(struct theImage, string cachedFilename, struct fileInfo, [string authenticationString=''], [numeric width='0'], [numeric height='0'], [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string backgroundColor])
         Spawn a new thread to resize an image.
    any setAllowedExtensions(array AllowedExtensions)
    any setAllowedMimeTypes(array AllowedMimeTypes)
    any setCacheFolder(string cacheFolder)
    any setCacheURL(string cacheURL)
    any setExecutorService(cfconcurrent.ExecutorService ExecutorService)
    any setImageMagickLocation(string imageMagickLocation)
    any setInterpolation(string interpolation)
    any setKeepFilenames(boolean keepFilenames)
    any setMaxHeight(numeric maxHeight)
    any setMaxThreads(numeric maxThreads)
    any setMaxWidth(numeric maxWidth)
    any setQueuedThreads(struct queuedThreads)
    any setRunningThreads(struct runningThreads)
    any setUseThreading(boolean useThreading)
    string writeImageToCache(any imageObject, string filename)
         Write an image to the cache folder.
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init()

    Constructor


    Property Detail

    AllowedExtensions

    property array AllowedExtensions

    AllowedExtensions

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    AllowedMimeTypes

    property array AllowedMimeTypes

    Supported mime types

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    cacheFolder

    property string cacheFolder

    Filesystem location of the folder in which to store cached images

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    cacheURL

    property string cacheURL = [cached]

    The URL of the cached folder This will be included in returned URLs

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    ExecutorService

    property cfconcurrent.ExecutorService ExecutorService

    An instance of CFConcurrent.ExecutorService - https://github.com/pixl8/cfconcurrent When available, ColdThumbs will use the CFConcurrent framework to handle threading over native CFThread

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    imageMagickLocation

    property string imageMagickLocation

    Set the location of an ImageMagick binary to use this over native Java image resizing.

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    interpolation

    property string interpolation = [mitchell]

    Interpolation to use when resizing images

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    keepFilenames

    property boolean keepFilenames = [true]

    Keep filenames. When true, the cached name will retain the original filename with a truncated hash. Use when it is desirable for keywords to be included in returned images.

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    maxHeight

    property numeric maxHeight = [5000]

    The maximum height an image may be output. Use this to avoid huge images that may hog server resources to generate

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    maxThreads

    property numeric maxThreads = [2]

    Maximum number of threads to spawn. Remaining image processing requests will be held in a queue.

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    maxWidth

    property numeric maxWidth = [5000]

    The maximum width an image may be output. Use this to avoid huge images that may hog server resources to generate

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    queuedThreads

    property struct queuedThreads

    Array to hold calls queued for processing

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    runningThreads

    property struct runningThreads

    Struct to hold information about resizing threads

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    useThreading

    property boolean useThreading = [true]

    Spawn new threads to resize images

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    checkCachedImageExists

    public boolean checkCachedImageExists(string filename)

    Checks the cache folder to see if a given file exists

    Parameters:
    filename - (required) The image file name
    Returns:
    Boolean

    checkCacheFolder

    public string checkCacheFolder()

    Create the cache folder if it doesn't exist

    Returns:
    Cache folder path

    generateCachedFilename

    public string generateCachedFilename(struct fileInfo, numeric width, numeric height, [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string extension=''])

    Generate a cached file name from image file info

    Parameters:
    fileInfo - Struct of image file information generated by the getLocalFileInfo or getRemoteFileInfo functions
    width - Width of cached file
    height - Height of cached file
    fixCanvas - Whether the fixCanvas flag was set
    interpolation - Interpolation to use for the resizing
    extension - Override the file extension
    Returns:
    Cached filename string

    getAllowedExtensions

    public string getAllowedExtensions()


    getAllowedMimeTypes

    public string getAllowedMimeTypes()


    getCacheFolder

    public any getCacheFolder()

    Override default getCacheFolder to run through normalise function

    Returns:
    Normalised cache folder location

    getCacheURL

    public string getCacheURL()


    getExecutorService

    public string getExecutorService()


    getImageFileInfo

    public any getImageFileInfo(string src, [string authenticationString=''])

    Get a struct of file info

    Parameters:
    src - (required) The location (path or URL) of the image
    authenticationString - An authentication string if one is required (user:pass)
    Returns:
    File info struct

    getImageMagickLocation

    public string getImageMagickLocation()


    getInterpolation

    public string getInterpolation()


    getKeepFilenames

    public string getKeepFilenames()


    getLocalFileInfo

    private struct getLocalFileInfo(string path)

    Get a struct of file info from a local path

    Parameters:
    path - (required) The path of the image
    Returns:
    File info struct

    getMaxHeight

    public string getMaxHeight()


    getMaxThreads

    public string getMaxThreads()


    getMaxWidth

    public string getMaxWidth()


    getMemento

    public any getMemento()

    getMemento


    getQueuedThreads

    public string getQueuedThreads()


    getRemoteFileInfo

    private struct getRemoteFileInfo(string url, [string authenticationString=''])

    Get a struct of file info from a remote URL

    Parameters:
    url - (required) The URL of the image
    authenticationString - An authentication string if one is required (user:pass)
    Returns:
    File info struct

    getRunningThreads

    public string getRunningThreads()


    getThumbnail

    public any getThumbnail(string src, [string authenticationString=''], [numeric width='0'], [numeric height='0'], [string imageType=''], [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string backgroundColor], [boolean regenerate='false'], [boolean useThreading='[runtime expression]'])

    Retrieve a thumbnail from the cache or generate a new one from source

    Parameters:
    src - (required) The location (path or URL) of the image
    authenticationString - An authentication string if one is required (user:pass)
    width - Width of cached file
    height - Height of cached file
    imageType - Convert the resized image to a different type: (JPG|GIF|PNG|BMP) - Matches the source image type by default.
    fixCanvas - When true, fix the canvas size to the specified dimensions, whilst proportionally resizing the content. e.g. You may want to create a uniform square image from a portrait or landscape image.
    interpolation - Interpolation to use for the resizing
    backgroundColor - When using the fixCanvas method, the resulting image may contain a blank area that should be filled with a colour. (hex or r,g,b)
    regenerate - When true, force the regeneration of the thumbnail overwriting an existing image in the cache
    useThreading - When true, the image will spawn a new thread in which the resize process will occur.

    getUseThreading

    public string getUseThreading()


    isRequestInThread

    private boolean isRequestInThread()

    Check to see if the current request is in a thread, as we can't have nested threads Thanks to Mark Mandel: https://www.compoundtheory.com/how-to-tell-if-code-is-being-run-inside-a-cfthread-tag/


    normalisePath

    private any normalisePath(string path)

    Normalise the file path by replacing back slashes and removing duplicates

    Parameters:
    path - (Required) the path to normalise
    Returns:
    String - normalised path.

    processQueue

    private any processQueue()

    Process images stored in the thread queue


    resizeImage

    private any resizeImage(struct theImage, string cachedFilename, struct fileInfo, numeric width, numeric height, [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string backgroundColor], [string authenticationString=''])

    Resize the image

    Parameters:
    theImage - The extended image object
    cachedFilename - The filename to use when saving the cached image
    fileInfo - A struct of file info
    width - Width of cached file
    height - Height of cached file
    fixCanvas - When true, fix the canvas size to the specified dimensions, whilst proportionally resizing the content. e.g. You may want to create a uniform square image from a portrait or landscape image.
    interpolation - Interpolation to use for the resizing
    backgroundColor - When using the fixCanvas method, the resulting image may contain a blank area that should be filled with a colour. (hex or r,g,b)
    authenticationString - An authentication string if one is required (user:pass)

    resizeImageInThread

    private any resizeImageInThread(struct theImage, string cachedFilename, struct fileInfo, [string authenticationString=''], [numeric width='0'], [numeric height='0'], [boolean fixCanvas='false'], [string interpolation='[runtime expression]'], [string backgroundColor])

    Spawn a new thread to resize an image

    Parameters:
    theImage - The extended image object
    cachedFilename - The filename to use when saving the cached image
    fileInfo - A struct of file info
    authenticationString - An authentication string if one is required (user:pass)
    width - Width of cached file
    height - Height of cached file
    fixCanvas - When true, fix the canvas size to the specified dimensions, whilst proportionally resizing the content. e.g. You may want to create a uniform square image from a portrait or landscape image.
    interpolation - Interpolation to use for the resizing
    backgroundColor - When using the fixCanvas method, the resulting image may contain a blank area that should be filled with a colour. (hex or r,g,b)

    setAllowedExtensions

    public any setAllowedExtensions(array AllowedExtensions)

    Parameters:
    AllowedExtensions

    setAllowedMimeTypes

    public any setAllowedMimeTypes(array AllowedMimeTypes)

    Parameters:
    AllowedMimeTypes

    setCacheFolder

    public any setCacheFolder(string cacheFolder)

    Parameters:
    cacheFolder

    setCacheURL

    public any setCacheURL(string cacheURL)

    Parameters:
    cacheURL

    setExecutorService

    public any setExecutorService(cfconcurrent.ExecutorService ExecutorService)

    Parameters:
    ExecutorService

    setImageMagickLocation

    public any setImageMagickLocation(string imageMagickLocation)

    Parameters:
    imageMagickLocation

    setInterpolation

    public any setInterpolation(string interpolation)

    Parameters:
    interpolation

    setKeepFilenames

    public any setKeepFilenames(boolean keepFilenames)

    Parameters:
    keepFilenames

    setMaxHeight

    public any setMaxHeight(numeric maxHeight)

    Parameters:
    maxHeight

    setMaxThreads

    public any setMaxThreads(numeric maxThreads)

    Parameters:
    maxThreads

    setMaxWidth

    public any setMaxWidth(numeric maxWidth)

    Parameters:
    maxWidth

    setQueuedThreads

    public any setQueuedThreads(struct queuedThreads)

    Parameters:
    queuedThreads

    setRunningThreads

    public any setRunningThreads(struct runningThreads)

    Parameters:
    runningThreads

    setUseThreading

    public any setUseThreading(boolean useThreading)

    Parameters:
    useThreading

    writeImageToCache

    public string writeImageToCache(any imageObject, string filename)

    Write an image to the cache folder

    Parameters:
    imageObject - (required) The image object to write to the cache
    filename - (required) The filename to use when writing to the cache
    Returns:
    Cached image path