I modified your code like this :
# Export Plugin
module.exports = (BasePlugin) ->
im = require('imagemagick')
# Define Plugin
class ImageMagickPlugin extends BasePlugin
# Plugin name
name: 'imagemagick'
config:
source: "images"
suffix: "_resized"
width: 256
writeAfter: (opts,next) ->
docpad = @docpad
config = @config
docpad.getDatabase().forEach (document) ->
attr = document.attributes
if attr.extension is 'jpg' and attr.relativeDirPath is config.source
srcPath = './src/files/' + attr.relativePath
dstPath = './out/' + config.source + "/" + attr.basename + config.suffix + ".jpg"
im.resize
srcPath: srcPath
dstPath: dstPath
width: config.width
, (err, stdout, stderr) ->
throw err if err
console.log "File resized: " + attr.filename
next()
This way, you loop over the files looking for jpg files in ./src/files/images/ and you write the resized version directly in the ./out/images/ with a modified name : foo.jpg is resized in foo_resized.jpg. By doing this, you don't "pollute" your src files.
If you just want to replace the source images by the resized ones in ./out/images/, you can simply define an empty string for the suffix in docpad.coffee
:
plugins:
imagemagick:
suffix: ""
width: 300
or just set it in the config object of the plugin!