     dst: mkPath root, dstPathOnServer
 
   fileExists(resizeOpts.dst).then (exists) ->
-    if exists
-      getImageInfo(resizeOpts.dst).then (existing) ->
-        process.stdout.write '-' unless quiet
-        existing
-    else
-      makeDirectories(path.dirname(resizeOpts.dst)).then ->
-        resizeImage(resizeOpts).spread (resized) ->
-          process.stdout.write '.' unless quiet
-          resized
+    magickSemaphore.push ->
+      if exists
+        getImageInfo(resizeOpts.dst).then (existing) ->
+          process.stdout.write '-' unless quiet
+          existing
+      else
+        makeDirectories(path.dirname(resizeOpts.dst)).then ->
+          resizeImage(resizeOpts).spread (resized) ->
+            process.stdout.write '.' unless quiet
+            resized
   .then (imageInfo) ->
     medium =
       width: parseInt imageInfo.width

  sizes = argv.size.map parseSize
  {concurrency, root, output, quiet} = argv

  Q.when null, ->
    if argv.path
      albums.find($or: [

    console.warn '\nFailed to create thumbnail:', resizeOpts.src

createPreviews = (opts) ->
  {albums, sizes, root, output, quiet} = opts

  albums.forEach (album) ->
    album.pictures.forEach (picture) ->
      sizes.forEach (size) ->
        do (album, picture, size) ->
          createPreview
            albumPath: album.path
            picture: picture
            size: size
            root: root
            output: output
            quiet: quiet

  magickSemaphore.finished

if require.main is module
  argv = require('optimist')
