docs: function adapt(callback) {
        /*
         * For Graphics Magick docs: http://www.graphicsmagick.org/GraphicsMagick.html#details-geometry
         * Inspiration: http://stackoverflow.com/questions/14705152/thumbnails-from-graphics-magick-without-upscaling
         */
  
        co(function*() {
          let externalStream = config.stream(path);
  
          if (!externalStream) {
            // Ensure the file exists on the filesystem.
            try {
              yield Q.nfcall(fs.stat, mkpath(imagesDir, matches.path));
            } catch (e) {
              return next();
            }
          }
  
          // Stream the image into a buffer. (passing a stream directly into GM was causing problems with gcloud streams)
          let stream = externalStream || fs.createReadStream(mkpath(imagesDir, path));
  
          try {
            var buffer = yield Q.nfcall(stream2buffer, stream);
          } catch (e) {
            return callback(e);
          }
  
          let img = gm(buffer);
          
          // Set up some options
          img
            // .filter('Triangle')
            // Not sure if these work in GM, but they are IM options
            // .define('filter:support=2')
            // .define('jpeg:fancy-upsampling=off')
            // .unsharp(0.25, 0.25, 8, 0.065)
            // .colors(136)
            // .dither(false)
            // .colorspace('sRGB')
            .out('-background', bg || (mimetype == 'image/png' ? 'transparent' : 'white'));
  
          img.size(function(err, nativeSize) {
            if (err || typeof nativeSize == 'undefined' || typeof nativeSize.width == 'undefined' || typeof nativeSize.height == 'undefined') {
              return callback(err || 'Failed to retrieve image dimensions.');
            }
  
            /**
             * Validate dimensions & determine sizing rules.
             */
            let imageWidth = width, imageHeight = height;       // The size of the image itself
            let canvasWidth = width, canvasHeight = height;     // The size of the canvas around the image
            let allowResize;
  
            // If we're resizing, ensure we never exceed the native image dimensions.
            if (!imageWidth && !imageHeight) {
              // Using native image size, no resizing necessary.
              imageWidth = nativeSize.width;
              imageHeight = nativeSize.height;
              canvasWidth = nativeSize.width;
              canvasHeight = nativeSize.height;
  
              allowResize = false;
            } else if ((imageWidth && !imageHeight) || (!imageWidth && imageHeight)) {
              // One size provided, scale the other proportionally.
              if (imageWidth) {
                imageHeight = Math.round(imageWidth * (nativeSize.height / nativeSize.width));
                canvasHeight = imageHeight >= nativeSize.height ? nativeSize.height : imageHeight;  // trim extra space from canvas height
              } else {
                imageWidth = Math.round(imageHeight * (nativeSize.width / nativeSize.height));
                canvasWidth = imageWidth >= nativeSize.width ? nativeSize.width : imageWidth;       // trim extra space from canvas width
              }
  
              allowResize = imageWidth < nativeSize.width && imageHeight < nativeSize.height;
            } else {
              // Two sizes provided.
              if (imageWidth > nativeSize.width && imageHeight > nativeSize.height) {
                // Do not exceed the native image size.
                imageWidth = nativeSize.width;
                imageHeight = nativeSize.height;
                allowResize = false;
              } else {
                if (imageWidth > nativeSize.width) {
                  // Preserve requested height, but correct the width.
                  imageWidth = 0;   // auto
                } else if (imageHeight > nativeSize.height) {
                  // Preserve requested width, but correct the height.
                  imageHeight = 0;  // auto
                }
  
                // Sizes are fine, fit into the requested box.
                allowResize = true;
              }
            }
  
            /**
             * Adapt the image.
             */
            
            if (mode == MODE_ASPECT_FILL) {
              img
                .resize(width, height, '^')
                .gravity('Center')
                .crop(width, height);
            } else if (mode == MODE_ASPECT_FIT) {
              if (allowResize) {
                let w = imageWidth == 0 ? null : (crop ? `${width}^` : imageWidth);
                let h = imageHeight == 0 ? null : (crop ? `${height}^` : imageHeight);
  
                img = img.resize(w, h);
              }
  
              img
                .gravity('Center')
                .extent(canvasWidth, canvasHeight);
            }
  
            img
              .quality(config.default.quality)
              .strip()
              .stream(function(err, stdout, stderr) {
                if (err) {
                  return callback(err);
                }
  
                // calling .trim() on a GM object seems to have no effect,
                // so we need to perform that on the buffer if necessary.
                if (!trim) {
                  return callback(null, stdout);
                }
  
                gm(stdout).trim().stream(function(err, stdout, stderr) {
                  if (err) {
                    return callback(err);
                  }
  
                  callback(null, stdout);
                });
              });
  
          }); // /size
        }); // /co
      }