Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sdepold/node-imageable
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: stipple/node-imageable
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 25, 2013

  1. add watermarking functionality

    mpd committed Sep 25, 2013
    Copy the full SHA
    a45155c View commit details
  2. Copy the full SHA
    08400c9 View commit details

Commits on Sep 26, 2013

  1. watermark gravity -> northwest now

    mpd committed Sep 26, 2013
    Copy the full SHA
    e553fba View commit details
Showing with 48 additions and 1 deletion.
  1. +47 −0 lib/image-magick.js
  2. +1 −1 lib/request-handler.js
47 changes: 47 additions & 0 deletions lib/image-magick.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ ImageMagick.Templates = {
resizeCmd: "-resize '%{size}'",
fitCmd: "-gravity center -resize '%{size}'^ -extent %{size}",
cropCmd: "-crop %{crop} +repage -thumbnail '%{size}'",
watermarkCmd: "-gravity northwest",

checkValue: function(value) {
if(!value.toString().match(/^[^;"']+$/i))
@@ -88,6 +89,13 @@ ImageMagick.prototype.crop = function(params, callback) {
}
}

ImageMagick.prototype.watermark = function(params, callback) {
// if(!params.hasOwnProperty('size'))
// throw new Error('Resize needs size-param with format <width>x<height>!')

this._composite(ImageMagick.Templates.get('watermarkCmd', {}), params, callback)
}

// private

ImageMagick.prototype.execute = function(cmd, options, callback) {
@@ -275,3 +283,42 @@ ImageMagick.prototype._convert = function(_command, params, callback) {
})
})
}

ImageMagick.prototype._composite = function(_command, params, callback) {
var source = params.url
, self = this
// , size = params.size || params.crop.split('+')[0]
, pathHashString
, srcTmpPath
, destTmpPath

srcTmpPath = this._createTmpPath(source)

pathHashString = source + ':' + _command

destTmpPath = this._createTmpPath(pathHashString)

this._localizeSource(source, srcTmpPath, function(err, exists, localizedSource) {
if(err && !exists)
return callback && callback(err, null, null)

self._getTempfile(localizedSource, destTmpPath, function(tmpfile) {
fs.exists(tmpfile, function(tmpFileExists) {
if(tmpFileExists) {
self.logger.log('Converted file already exists. Skipping composite')
callback(null, tmpfile)
} else {
self.logger.log('Converted file does not exist. Converting...')
var command = "convert -composite " + _command + " '" + localizedSource + "' /data/watermark/shared/watermark.png '" + tmpfile + "'"

if(!exists)
command = self._getFallbackImageCommand(size, tmpfile)

self.execute(command, { timeout: self.config.timeouts.convert }, function (err, stdout, stderr) {
callback && callback(err, tmpfile)
})
}
})
})
})
}
2 changes: 1 addition & 1 deletion lib/request-handler.js
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ RequestHandler.prototype.isImageProcessUrl = function(req) {
}

RequestHandler.prototype.getImageProcessUrlRegExp = function() {
var template = "^\/(identify|resize|crop|fit)(\/([^\/\?]+))?"
var template = "^\/(watermark|identify|resize|crop|fit)(\/([^\/\?]+))?"

if (this.config.hasOwnProperty('namespace') && (this.config.namespace != ''))
template = template.replace("^", "^\/" + this.config.namespace)