Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
domains
public
test
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://dadi.tech/assets/products/dadi-cdn-full.png" alt="DADI CDN" height="65"/>
<img src="https://dadi.cloud/assets/products/dadi-cdn-full.png" alt="DADI CDN" height="65"/>

[![npm (scoped)](https://img.shields.io/npm/v/@dadi/cdn.svg?maxAge=10800&style=flat-square)](https://www.npmjs.com/package/@dadi/cdn)
[![coverage](https://img.shields.io/badge/coverage-88%25-yellow.svg?style=flat)](https://github.com/dadi/cdn)
Expand Down Expand Up @@ -32,7 +32,7 @@ CDN is part of DADI, a suite of components covering the full development stack,

### Install dependencies

Ensure you have the required dependencies installed. See the first sections in the CDN [installation](https://docs.dadi.tech/cdn) documentation.
Ensure you have the required dependencies installed. See the first sections in the CDN [installation](https://docs.dadi.cloud/cdn) documentation.

### Install CDN

Expand Down Expand Up @@ -68,7 +68,7 @@ With the default configuration, our CDN server is available at http://localhost:

CDN requires a configuration file specific to the application environment. For example in the production environment it will look for a file named `config.production.json`.

When CDN was installed, a development configuration file was created for you in a `config` folder at your application root. Full configuration documentation can be found at https://docs.dadi.tech/cdn.
When CDN was installed, a development configuration file was created for you in a `config` folder at your application root. Full configuration documentation can be found at https://docs.dadi.cloud/cdn.


### Run CDN as a service
Expand All @@ -84,7 +84,7 @@ $ forever-service install -s index.js -e NODE_ENV=production cdn --start

### Configuring an image source

Before you can serve assets or images you need to tell CDN where your files are located. Currently, CDN can serve your files from three types of source: [Amazon S3](https://docs.dadi.tech/cdn/#amazon-s3), [a remote server](https://docs.dadi.tech/cdn/#remote-server), and the [the local filesystem](https://docs.dadi.tech/cdn/#local-filesystem). We'll start using the local filesystem, but see the [full documentation](https://docs.dadi.tech/cdn/#defining-sources) for details on using the other source types.
Before you can serve assets or images you need to tell CDN where your files are located. Currently, CDN can serve your files from three types of source: [Amazon S3](https://docs.dadi.cloud/cdn/#amazon-s3), [a remote server](https://docs.dadi.cloud/cdn/#remote-server), and the [the local filesystem](https://docs.dadi.cloud/cdn/#local-filesystem). We'll start using the local filesystem, but see the [full documentation](https://docs.dadi.cloud/cdn/#defining-sources) for details on using the other source types.

The sample configuration file defines a local filesystem source. The `path` property is set to use an directory called `images` at the root of your application. CDN will look for your files at the location defined in this `path` property every time it handles a request.

Expand Down Expand Up @@ -123,14 +123,14 @@ drwxr-xr-x 4 root wheel 136 13 Mar 13:01 ..
http://127.0.0.1:8001/92875.jpg

## Links
* [CDN Documentation](https://docs.dadi.tech/cdn)
* [CDN Documentation](https://docs.dadi.cloud/cdn)

## Licence

DADI is a data centric development and delivery stack, built specifically in support of the principles of API first and COPE.

Copyright notice<br />
(C) 2018 DADI+ Limited <support@dadi.tech><br />
(C) 2018 DADI+ Limited <support@dadi.cloud><br />
All rights reserved

This product is part of DADI.<br />
Expand Down
12 changes: 9 additions & 3 deletions dadi/lib/handlers/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ ImageHandler.prototype.getDimensions = function (options, imageInfo) {
height: imageInfo.naturalHeight
}
let ratio = imageInfo.naturalHeight / imageInfo.naturalWidth

const ratioOverride = Boolean(options.ratio) && options.ratio.match(/^(\d+)-(\d+)$/)
let ratioOverride = Boolean(options.ratio) && options.ratio.match(/^(\d+)-(\d+)$/)

// Is there an explicit ratio defined?
if (ratioOverride) {
Expand Down Expand Up @@ -613,6 +612,11 @@ ImageHandler.prototype.getDimensions = function (options, imageInfo) {
dimensions.width = Math.min(dimensions.width, config.get('security.maxWidth'))
dimensions.height = Math.min(dimensions.height, config.get('security.maxHeight'))

if (options.devicePixelRatio && options.devicePixelRatio < 4) {
dimensions.width = dimensions.width * options.devicePixelRatio
dimensions.height = dimensions.height * options.devicePixelRatio
}

return dimensions
}

Expand Down Expand Up @@ -758,7 +762,9 @@ ImageHandler.prototype.process = function (imageBuffer, options, imageInfo) {
// Default values fot resize style
if (!options.resizeStyle) {
if (options.width && options.height) {
options.resizeStyle = 'entropy'
options.resizeStyle = options.gravity
? 'aspectfill'
: 'entropy'
} else {
options.resizeStyle = 'aspectfit'
}
Expand Down
17 changes: 17 additions & 0 deletions test/acceptance/visual_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@
},
"baselineFilename": "images/visual/baseline/measure.png?sharpen=5.png"
},
{
"image": "measure1.png",
"params": {
"width": 250,
"height": 150,
"gravity": "southwest"
},
"baselineFilename": "images/visual/baseline/measure.png?width=250&height=150&gravity=southwest.png"
},
{
"image": "measure1.png",
"params": {
"width": 250,
"dpr": 3
},
"baselineFilename": "images/visual/baseline/measure.png?width=250&dpr=3.png"
},
{
"image": "measure1.png",
"params": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.