5.3.2 • Published 8 years ago

pointr v5.3.2

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

Pointr

A simple image service using Node.js, Express, GraphicsMagick, and OpenCV.

What's it do?

  • (Re)sizing, cropping
  • Image formatting (JPG, PNG, ...)
  • Reduce quality (for fast downloads)
  • Filters (brightness, hue, contrast, blur, ...)

Installation

  1. Install Node.js
  2. Install GraphicsMagick
  3. Install OpenCV
  4. npm install
  5. Create a config YAML file based on the config.example.yml

Running

bin/pointr production_config.yml

Configuration

Pointr uses a config file to control all options. See config.example.yml as an example and for more details.

Config Option
portOptional. Defaults to 3000. The port to run the service on.
log.jsonOptional. Defaults to true. Whether to use JSON for output logging.
log.colorizeOptional. Defaults to false. Whether to color the log.
log.levelOptional. Defaults to debug. The logging level.
log.disableAccessLoggingOptional. Defaults to false. Whether to disable access logging.
tempDirOptional. Defaults to system temp dir. Where to put temporary images being processed.
validHostnamesOptional. A list of valid host names the service will respond to.
instances.minOptional. Defaults to 2. The minimum number of instances to start.
instances.maxOptional. Defaults to 128. The maximum number of instances to start.
requestTimeoutOptional. Defaults to 5. Timeout (in seconds) when requesting images.
downloader.userAgentOptional. Defaults to pointr. A user agent header string to use when downloading images.
cache.ttlDefaultRecommended. Defaults to 2592000 (30 days). Cache time if cache control is not present in image response.
cache.ttlMinRecommended. Defaults to 3600 (one hour). Minimum cache time for the Cache-Control header.
cache.ttlMaxRecommended. Defaults to 2592000 (30 days). Maximum cache time for the Cache-Control header.
trustProxyOptional. The trust proxy setting fot the express server.
errors.blankImages.enabledOptional. Defaults to false. Whether to return blank images in error cases.
errors.blankImages.ttlOptional. Defaults to 30 seconds. The blank image TTL in seconds.
errors.blankImages.statusCodeOptional. Defaults to 204. The status code for blank images.
ipHeaderRecommended. The header to use for the end-client (browser) IP address.
rateLimiterRecommended. A rate limiter to use. See config.example.yml for an example.
clientsRequired. The set of clients that will be using the service. See config.example.yml for an example.

The cache configuration above can also be set per client. See the example configuration below.

Example Configuration

# Optional. Defaults to 3000. The port for the service to run on.
port: 3000

# Optional. Logging configuration
log:
  json: true                  # Use JSON logging
  colorize: false             # Do not color the logs
  level: debug                # Log level
  disableAccessLogging: false # Whether to disable access logging

# Optional. Defaults to the system temp directory.
tempDir: /tmp

# Optional. A list of valid hostnames for the service.
# This is useful if you want to hide the origin hostname (e.g. s3cr3th0s1.example.com).
validHostnames:
  - localhost

# Optional. The number of pointr instances to run.
# This will default to the number of CPUs on the system bounded by the min and max.
instances:
  min: 2
  max: 64

# Optional. Timeout (in seconds) when requesting images.
requestTimeout: 5

# Recommended. The header to use for the end-client (browser) IP address.
# This is necessary if this service is an origin,
# fronted by a CDN that provides its own header for the client IP address.
# For example, Akamai provides a "True-Client-IP" header.
ipHeader: True-Client-IP

# How long to cache images. This will set the cache control header for the CDN.
cache: 
  ttlDefault: 2592000   # Default to 30 days (2592000 seconds).
  ttlMin: 3600          # Minimum 1 hour (3600 seconds).
  ttlMax: 2592000       # Maximum 30 days (2592000 seconds).

# Recommended. The rate limiter to use.
# The rate limiter should have a type (key) to a set of options.
rateLimiter:

  # Use a redis rate limiter.
  redis:
    # Required. The host where the redis instance lives.
    host: localhost
    # Required. The port the redis instance is running on.
    port: 6379
    # Optional. The redis password.
    # pass: 3x@mp13

# The set of clients that will be using the service.
# Each client is a key to a set of options for that client.
clients:

  # A demo client. A unsafe, rate limited client for demo purposes.
  demo:
    # Client-specific cache time settings.
    cache:
      ttlDefault: 3600
      ttlMin: 3600
      ttlMax: 3600
    # Allow requests without a signature.
    unsafe: true
    # Rate limit by end-client (browser) IP; allow 10 reqs per hour.
    rateLimit: { by: ip, max: 10, perHours: 1 }

  # An example of an internal tool that has no rate limit
  # because the secret key is not exposed.
  internal_tool:
    # Use this secret key for generating signatures.
    secret: "1nt3rn@lT00l"
    # No rate limit.
    rateLimit: none

  # An example of a client that has a secret in addition to a
  # rate limit.
  mobile:
    # Use this secret key for generating signatures.
    secret: "M0b1l3*1m@g3*R351z1ng!"
    # Rate limit by end-client (browser) IP; allow 1000 reqs per hour.
    rateLimit: { by: ip, max: 1000, perHours: 1 }

API

The Pointr API takes a client key, followed by an optional security signature (depending on whether a secret was configured for the application, see the configuration example), followed by a sequence of operations, followed by the image URL to manipulate.

The format looks like the following:

http://<pointr_service_host>/<client>[:<signature>]/<operation1>/<operation2>/.../?url=<url_encoded_image_url>

Signature

To access the API through an safe client (one that uses a secret, see config above), you must generate a signature.

To generate a security signature, you generate a SHA-1 HMAC (Hashed Message Authentication Code) of the portion of the URL that comes after the client and signature.

Format: <operation1>/<operation2>/.../?url<url_encoded_image_url> Example: thumb:300,300/flip:h/?url=http%3A%2F%2Fexample.com%2Fmy-image.jpeg

If the above string of operations and image URL is message, The algorithm looks like the following:

Examples

Pseudocode

signature = sha1_hmac_hex(clientSecret, message)
Node.js
var crypto = require('crypto');
var signature = crypto.createHmac('sha1', clientSecret).update(message).digest('hex');`
PHP
$signature = hash_hmac('sha1', $message, $clientSecret);

Making Requests

Once the signature is computed, you can make requests using the client ID and signature in the URL:

http://<pointr_service_host>/<client>:<signature>/<operation1>/<operation2>/.../?url=<url_encoded_image_url>

Operations

Operations contain a name, followed by a colon :, followed by a comma-delimited list of parameters.

The format looks like the following:

<operation_name>:<param1>,<param2>,...


resize, r

Resize the image to the given size.

http://<host>/<client>[:<signature>]/resize:<width>,<height>[,<options>]/<image_url>

http://<host>/<client>[:<signature>]/resize:500,300/<image_url>
http://<host>/<client>[:<signature>]/r:600,250,force/<image_url>
Argument
widthThe width.
heightThe height.
optionsComma-delimited options for the resize (see below).
Resize Options
Options
forceForce the resize to the width and height specified.
shrinkOnly resize the image if it will shrink.
growOnly resize the image if it will grow.
minTreat the width/height as minimum values instead of maximum values.
percentTreat the width/height as percentages.

thumb, t

Create a thumbnail for the given size (takes the focal point into consideration).

Thumbnails will automatically crop the image, trying to get as much in the frame as possible.
If not all of the image can fit, the focal point will be used as the center point for the crop while keeping the image within the bounds.

http://<host>/<client>[:<signature>]/thumb:<width>,<height>/<image_url>

http://<host>/<client>[:<signature>]/thumb:500,300/<image_url>
http://<host>/<client>[:<signature>]/t:600,250/<image_url>
Argument
widthThe width for the thumbnail (in pixels).
heightThe height for the thumbnail (in pixels).

crop, c

Crop the image to the given size and offset.

The width, height, and x and y offsets are absolute pixel values based on the original image.

http://<host>/<client>[:<signature>]/crop:<width>,<height>,<x>,<y>/<image_url>

http://<host>/<client>[:<signature>]/crop:300,500,30,30/<image_url>
Argument
widthThe width for the crop (in pixels).
heightThe height for the crop (in pixels).
xThe horizontal offset for the crop from the left of the image (in pixels).
yThe vertical offset for the crop from the top of the image (in pixels).

flip, p

Flip the image along the given direction (h for horizontal or v for vertical).

http://<host>/<client>[:<signature>]/flip:<direction>/<image_url>

http://<host>/<client>[:<signature>]/flip:v/<image_url>
http://<host>/<client>[:<signature>]/p:h/<image_url>
Argument
directionThe direction to perform the flip (h for horizontal or v for vertical).

focal, foc

Set the focal point for the image based on detection algorithms.

Specifying auto will use a predefined detection list. The first detection to match will be used as the focal point.
The list can contain face, eye, eyeglasses, etc. See below for the full list

If the detection returns more than one match, the center of mass of all matches will be calculated and used as the center point.

http://<host>/<client>[:<signature>]/focal:<detection_list>/<image_url>

http://<host>/<client>[:<signature>]/focal:auto/<image_url>
http://<host>/<client>[:<signature>]/foc:face,car_side,eye/<image_url>
Argument
detection_listA comma-delimited list of detection algorithms to check. Uses the first one that matches.

face, eye, eyeglasses, full_body, car_side, interesting_points.

Supported Detection Algorithms
Detections
faceLooks for frontal facial match(es).
eyeLooks for eye match(es).
eyeglassesLooks for eyeglass match(es).
full_bodyLooks for full body match(es).
car_sideLooks for car (automobile) side match(es).
interesting_pointsLooks for interesting points with good contrast.

rotate, o

Rotate the image to the given angle.

http://<host>/<client>[:<signature>]/rotate:<degrees>[,<background>]/<image_url>

http://<host>/<client>[:<signature>]/rotate:60/<image_url>
http://<host>/<client>[:<signature>]/o:45,ccc/<image_url>
Argument
degreesThe angle to use for the image rotation in degrees (0 to 360).
backgroundThe background color to use for empty space (if any). This should be a hex color, such as f00 (red) or 00ff00 (green).

format, f

Set the output format for the image.

http://<host>/<client>[:<signature>]/format:<image_format>/<image_url>

http://<host>/<client>[:<signature>]/f:jpg/<image_url>
http://<host>/<client>[:<signature>]/f:png/<image_url>
Argument
image_formatThe format for the image image (see below for all supported formats).
Supported Image Formats
Format
jpgJoint Photographic Experts Group JFIF format (JPEG)
pngPortable Network Graphics (PNG)
gifCompuServe Graphics Interchange Format (GIF)
bmpMicrosoft Windows Bitmap
tiffTagged Image File Format

quality, q

Set the quality for the image being output. Lower quality images reduce download size.

Quality can only be set if the image format is one of jpg, png, or tiff.

http://<host>/<client>[:<signature>]/quality:<percent>/<image_url>

http://<host>/<client>[:<signature>]/quality:35/<image_url>
http://<host>/<client>[:<signature>]/q:85/<image_url>
Argument
percentThe quality percent (0 to 100).
5.3.2

8 years ago

5.3.1

8 years ago

5.3.0

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.4

8 years ago

5.0.3

8 years ago

5.0.2

8 years ago

5.0.1

8 years ago

5.0.0

8 years ago

4.1.0

8 years ago

4.0.0

8 years ago

4.0.1

8 years ago

3.6.0

9 years ago

3.4.0

9 years ago

3.3.0

9 years ago

3.2.2

9 years ago

3.2.1

9 years ago

3.2.0

9 years ago

3.1.5

9 years ago

3.1.4

9 years ago

3.1.3

9 years ago

3.1.2

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.8.0

9 years ago

2.7.0

9 years ago

2.6.0

9 years ago

2.5.0

9 years ago

2.4.2

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.3.2

9 years ago

2.3.1

9 years ago

2.3.0

9 years ago

2.1.2

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.5.1

9 years ago

1.5.0

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago