api/images

module:api/images

Description:
  • Saving and serving images

Source:

Methods

(static) del(id, options, callback)

Description:
  • Delete an icon for user, .type defines icon prefix

Source:
Parameters:
Name Type Description
id string
options object
callback function

(static) getPath(id, options) → {string}

Description:
  • Full path to the icon, perform necessary hashing and sharding, id can be a number or any string.

Source:
Parameters:
Name Type Description
id string
options object
Properties
Name Type Attributes Description
type string <optional>

may contain special placeholders:

  • @uuid@ - will be replaced with a unique UUID and placed back to the options.type
  • @now@ - will be replaced with the current timestamp
  • @filename@ - will be replaced with the basename of the uploaded file from the filename property if present
Returns:
Type Description
string

(static) getUrl(file, options) → {string}

Description:
  • Returns constructed icon url from the icon record

Source:
Parameters:
Name Type Description
file string
options object
Returns:
Type Description
string

(static) isImage(buf) → {string}

Description:
  • Returns detected image type if the given buffer contains an image, it checks the header only

Source:
Parameters:
Name Type Description
buf buffer
Returns:
Type Description
string

(static) isUrl(url) → {boolean}

Description:
  • Return true if the given file or url point ot an image

Source:
Parameters:
Name Type Description
url string
Returns:
Type Description
boolean

(static) put(req, name, id, options, callback)

Description:
  • Store an icon for user, the options are the same as for the path method

Source:
Parameters:
Name Type Description
req Request
name string

is the name property to look for in the multipart body or in the request body or query

id string

is used in iconPath along with the options to build the icon absolute path

options object
Properties
Name Type Attributes Description
autodel boolean <optional>

if true, auto delete the base64 icon property from the query or the body after it is decoded, this is to mark it for deallocation while the icon is being processed, the worker queue is limited so with large number of requests all these query objects will remain in the query wasting memory

verify boolean <optional>

check the given image of file header for known image types

extkeep regexp <optional>

a regexp with image types to preserve, not to convert into the specified image type

ext string <optional>

the output file extention without dot, ex: jpg, png, gif....

callback function

(static) save(file, id, options, callback)

Description:
  • Save the icon data to the destination, if mod.s3 or options.imagesS3 specified then plave the image on the S3 drive. Store in the proper location according to the types for given id, this function is used after downloading new image or when moving images from other places. On success the callback will be called with the second argument set to the output file name where the image has been saved.

Source:
Parameters:
Name Type Description
file string
id string
options object

same properties as in module:api/images.scale: width, height, filter, ext, quality

Properties
Name Type Attributes Description
type string <optional>

icon type, this will be prepended to the name of the icon, there are several special types: - @uuid@ - auto generate an UUID - @now@ - use current timestamp - @filename@ - if filename is present the basename without extension will be used

prefix string <optional>

top level subdirectory under images/

filesize int <optional>

file size if available

filename string <optional>

name of a file uploaded if available

callback function

(static) scale(infile, options, callback)

Description:
  • Scale image return err if failed.

    If image module is not set (default) then the input data is returned or saved as is.

Source:
Parameters:
Name Type Description
infile string

can be a string with file name or a Buffer with actual image data

options object
Properties
Name Type Attributes Description
outfile string <optional>

if not empty is a file name where to store scaled image or if empty the new image contents will be returned in the callback as a buffer

width int <optional>

new width

height int <optional>

new image height

  • if width or height is negative this means do not perform upscale, keep the original size if smaller than given positive value,
  • if any is 0 that means keep the original size
ext string <optional>

image format: png, gif, jpg, svg

callback function

takes 3 arguments: function(err, data, info) where data will contain a new image data and info is an object with the info about the new or unmodified image: ext, width, height.

(static) send(req, id, options)

Description:
  • Send an icon to the client, only handles files

Source:
Parameters:
Name Type Description
req Request
id string
options object