Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DeepZoom support #146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
The typical use case for this high speed Node.js module is to convert large images of many formats to smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.

This module supports reading and writing JPEG, PNG and WebP images to and from Streams, Buffer objects and the filesystem.
It also supports reading images of many other types from the filesystem via libmagick or libgraphicsmagick if present.
It also supports reading images of many other types from the filesystem via libmagick, libgraphicsmagick or [OpenSlide](http://openslide.org/) if present and writing Deep Zoom images.
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.

Only small regions of uncompressed image data are held in memory and processed at a time, taking full advantage of multiple CPU cores and L1/L2/L3 cache. Resizing an image is typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings.
Expand All @@ -34,6 +34,7 @@ This module is powered by the blazingly fast [libvips](https://github.com/jcupit
* Node.js v0.10+ or io.js
* [libvips](https://github.com/jcupitt/libvips) v7.40.0+ (7.42.0+ recommended)
* C++11 compatible compiler such as gcc 4.6+ or clang 3.0+
* [OpenSlide](http://openslide.org/) 3.4.0+ for reading OpenSlide images (optional)

To install the most suitable version of libvips on the following Operating Systems:

Expand All @@ -48,6 +49,8 @@ To install the most suitable version of libvips on the following Operating Syste
* RHEL/Centos/Scientific 6, 7
* Fedora 21, 22
* Amazon Linux 2014.09
* OpenSuse Linux
* OpenSuse 13.1, 13.2

run the following as a user with `sudo` access:

Expand All @@ -57,6 +60,14 @@ or run the following as `root`:

curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | bash -

To enable OpenSlide, add the --with-openslide argument:

> curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | sudo bash -s -- --with-openslide

or run the following as `root`:

curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | bash -s -- --with-openslide

The [preinstall.sh](https://github.com/lovell/sharp/blob/master/preinstall.sh) script requires `curl` and `pkg-config`.

### Mac OS tips
Expand Down Expand Up @@ -508,11 +519,17 @@ _Requires libvips 7.42.0+_

An advanced setting to disable adaptive row filtering for the lossless PNG output format.

#### tileSize(tileSize)
Setting the tile_size when DZI output format is selected. Default is 256.

#### tileOverlap(tileOverlap)
Setting the overlap when DZI output format is selected. Default is 0.

### Output methods

#### toFile(filename, [callback])

`filename` is a String containing the filename to write the image data to. The format is inferred from the extension, with JPEG, PNG, WebP and TIFF supported.
`filename` is a String containing the filename to write the image data to. The format is inferred from the extension, with JPEG, PNG, WebP, TIFF and DZI supported.

`callback`, if present, is called with two arguments `(err, info)` where:

Expand Down
38 changes: 37 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ var Sharp = function(input) {
withoutAdaptiveFiltering: false,
withoutChromaSubsampling: false,
streamOut: false,
withMetadata: false
withMetadata: false,
tileSize: 256,
tileOverlap: 0
};
if (typeof input === 'string') {
// input=file
Expand Down Expand Up @@ -377,6 +379,32 @@ Sharp.prototype.withMetadata = function(withMetadata) {
return this;
};

/*
dz tile size for DZ output
max is 8192 since 7.36.5 (1024 before)
*/
Sharp.prototype.tileSize = function(tileSize) {
if (!Number.isNaN(tileSize) && tileSize >= 1 && tileSize <= 8192) {
this.options.tileSize = tileSize;
} else {
throw new Error('Invalid tileSize (1 to 8192) ' + tileSize);
}
return this;
};

/*
dz overlap for DZ output
*/
Sharp.prototype.tileOverlap = function(tileOverlap) {
if (!Number.isNaN(tileOverlap) && tileOverlap >=0 && tileOverlap <= 8192) {
this.options.tileOverlap = tileOverlap;
} else {
throw new Error('Invalid tileOverlap (0 to 8192) ' + tileOverlap);
}

return this;
};

Sharp.prototype.resize = function(width, height) {
if (!width) {
this.options.width = -1;
Expand Down Expand Up @@ -483,6 +511,14 @@ Sharp.prototype.raw = function() {
return this;
};

/*
Force DZI output
*/
Sharp.prototype.dz = function() {
this.options.output = '__dzi';
return this;
};

/*
Force output to a given format
@param format is either the id as a String or an Object with an 'id' attribute
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Brandon Aaron <hello.brandon@aaron.sh>",
"Andreas Lind <andreas@one.com>",
"Maurus Cuelenaere <mcuelenaere@gmail.com>",
"Linus Unnebäck <linus@folkdatorn.se>"
"Linus Unnebäck <linus@folkdatorn.se>",
"Victor Mateevitsi <mvictoras@gmail.com>"
],
"description": "High performance Node.js module to resize JPEG, PNG, WebP and TIFF images using the libvips library",
"scripts": {
Expand Down