OpenVeo server API for plugins

API Docs for: 4.3.1
Show:

imageProcessorMiddleware

Summary

Defines an expressJS middleware to process images.

var openVeoApi = require('@openveo/api');
expressApp.use('/mount-path', openVeoApi.middlewares.imageProcessorMiddleware(
  '/path/to/the/folder/containing/images'
  '/path/to/the/folder/containing/processed/images/cache'
  [
    {
      id: 'my-thumb', // Id of the style to apply when requesting an image processing
      width: 200, // Expected width (in px) of the image
      quality: 50 // Expected quality from 0 to 100 (default to 90 with 100 the best)
    }
  ]
));

// Then it's possible to apply style "my-thumb" to the image /mount-path/my-image.jpg using
// parameter "style": /mount-path/my-image.jpg?style=my-thumb

If path corresponds to an image with a parameter "style", the style is applied to the image before returning it to the client. Actually only one type of manipulation can be applied to an image: generate a thumbnail. If path does not correspond to an image the processor is skipped.

Constructor

imageProcessorMiddleware

Syntax

imageProcessorMiddleware

(
  • imagesDirectory
  • cacheDirectory
  • styles
  • headers
)
Function static

Summary

Parameters:

  • imagesDirectory String

    The path of the directory containing the images to process

  • cacheDirectory String

    The path of the directory containing already processed images (for cache purpose)

  • styles Array

    The list of available styles to process images with for each style:

    • [String] id Id of the style to apply when requesting an image processing
    • [Number] [width] Expected width of the image (in px) (default to 10)
    • [Number] [quality] Expected quality from 0 to 100 (default to 90 with 100 the best)
  • headers Object

    The name / value list of headers to send with the image when responding to the client

Returns:

Function:

The ExpressJS middleware

Item Index

Methods

generateThumbnail

Syntax

generateThumbnail

(
  • imagePath
  • cachePath
  • [width]
  • [quality]
)
Function private

Summary

Generates a thumbnail from the the given image.

Parameters:

  • imagePath String

    The image absolute path

  • cachePath String

    The image cache path

  • [width] Number optional

    The expected image width (in px) (default to 10)

  • [quality] Number optional

    Expected quality from 0 to 100 (default to 90 with 100 the best)

Returns:

Function:

callback Function to call when its done with:

  • Error An error if something went wrong