DOCS: CanvasView#exportImage(path, callback);
960808
function(path, callback) {
            this.update();
            var out = fs.createWriteStream(path),
                stream = this._element.createPNGStream();
            // Pipe the png stream to the write stream:
            stream.pipe(out);
            if (callback) {
                out.on('close', callback);
            }
            return out;
        }
56689
function (callback) {
        if (!self._image) {
          var paths = (process.env.PATH || '').split(delimiter);
          if (!_.find(paths, function(p) {
            if (fs.existsSync(p + '/imagecrunch')) {
              self._image = require('./lib/image/imagecrunch.js')();
              return true;
            }
            // Allow for Windows and Unix filenames for identify. Silly oversight
            // after getting delimiter right (:
            if (fs.existsSync(p + '/identify') || fs.existsSync(p + '/identify.exe')) {
              self._image = require('./lib/image/imagemagick.js')();
              return true;
            }
          })) {
            // Fall back to jimp, no need for an error
            self._image = require('./lib/image/jimp.js')();
          }
        }
        return callback(null);
      }
641667
function() {
      //to generate a PDF we first need to generate the canvas as done in generatePNG
      //just don't need to download the PNG
      this.generatePNG(false); 
      setTimeout(function(){ 
        html2canvas($("#canvas"), {
             onrendered: function(canvas) { 
              var canvas = document.getElementById("canvas");
              var imgData = canvas.toDataURL(
               'image/png');              
              var doc = new jsPDF('p', 'mm');
              doc.addImage(imgData, 'PNG', 0, 0);
              doc.save('clinical-timeline.pdf');
            }
        });
      }, 50); //wait for 50ms for the canvas to be rendered before saving the PDF
    }
215129
function downloadImage(map) {
    map.exportAsImage(function (url) {
        let a = document.createElement("a");
        a.download = "example";
        a.href = url;
        a.click();
    }, "jpeg");
}
1357951
def export(canvas)
      image = Magick::Image.new(canvas.width, canvas.height)
      image.import_pixels(0, 0, canvas.width, canvas.height, "RGBA", canvas.pixels.pack("N*"))
      image
    end
1271413
function exports(_selection){
            _selection.each(function(_data){
                chartWidth = width - margin.left - margin.right;
                chartHeight = height - margin.top - margin.bottom;
                data = cleanData(cloneData(_data));

                buildScales();
                buildAxis();
                buildSVG(this);
                buildGradient();
                buildBrush();
                drawArea();
                drawAxis();
                drawBrush();
                drawHandles();
            });
        }
1011500
private static void returnBitmapInto(final Bitmap bitmap, final String path, final Object into) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                if (into != null && path != null && bitmap != null) {
                    if (into instanceof ImageView) {
                        Log.d(TAG, "return bitmap " + path + " into ImageView");
                        ((ImageView) into).setImageBitmap(bitmap);
                    } else if (into instanceof Callback) {
                        Log.d(TAG, "return bitmap " + path + " into Callback");
                        ((Callback) into).onBitmapLoaded(path, bitmap);
                    }
                }
            }
        });
    }
852363
function(callback) {
      if (imagesPaths.length >= numberOfColumns * numberOfRows) return callback();

      var transparentImagePath = path.join(temporaryDirectoryPath, 'transparent.png');
      gm(width, height, '#00000000').write(transparentImagePath, function(error) {

        // Add as many as needed transparent images to the list of images
        var totalMissingImages = numberOfColumns * numberOfRows - imagesPaths.length;

        for (var i = 0; i < totalMissingImages; i++)
          imagesPaths.push(transparentImagePath);

        callback(error);
      });
    }
145935
function(callback) {

      if (this.filters.length === 0) {
        this.setElement(this._originalImage);
        callback && callback();
        return;
      }

      var isLikelyNode = typeof Buffer !== 'undefined' && typeof window === 'undefined',
          imgEl = this._originalImage,
          canvasEl = fabric.document.createElement('canvas'),
          replacement = isLikelyNode ? new (require('canvas').Image) : fabric.document.createElement('img'),
          _this = this;

        if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') {
          G_vmlCanvasManager.initElement(canvasEl);
        }

      canvasEl.width = imgEl.width;
      canvasEl.height = imgEl.height;

      canvasEl.getContext('2d').drawImage(imgEl, 0, 0, imgEl.width, imgEl.height);

      this.filters.forEach(function(filter) {
        filter && filter.applyTo(canvasEl);
      });

       /** @ignore */
      replacement.onload = function() {
        _this._element = replacement;
        callback && callback();
        replacement.onload = canvasEl = imgEl = null;
      };
      replacement.width = imgEl.width;
      replacement.height = imgEl.height;

      if (isLikelyNode) {
        var base64str = canvasEl.toDataURL('image/png').replace(/data:image\/png;base64,/, '');
        replacement.src = new Buffer(base64str, 'base64');
        _this._element = replacement;

        // onload doesn't fire in node, so we invoke callback manually
        callback && callback();
      }
      else {
        replacement.src = canvasEl.toDataURL('image/png');
      }

      return this;
    }
1323560
function BuildAssetsMiddleware (context)
{
  var grunt = context.grunt
    , options = context.options.assets;

  /**
   * Records which files have been already exported.
   * Prevents duplicate asset exports.
   * It's a map of absolute file names to boolean `true`.
   * @type {Object.<string,boolean>}
   */
  var exportedAssets = {};

  //--------------------------------------------------------------------------------------------------------------------
  // PUBLIC API
  //--------------------------------------------------------------------------------------------------------------------

  this.analyze = function (filesArray)
  {
    /* jshint unused: vars */
    // Do nothing
  };

  this.trace = function (module)
  {
    /* jshint unused: vars */
    // Do nothing.
  };

  this.build = function (targetScript)
  {
    if (!options.enabled) return;
    // Import file paths.
    var stylehseets = grunt.config (context.options.requiredStylesheets.exportToConfigProperty);
    if (!stylehseets) return; // No stylesheet sources are configured.
    var targetPath = path.dirname (targetScript);
    stylehseets.forEach (function (filePath)
    {
      var src = grunt.file.read (filePath);
      scan (path.dirname (filePath), targetPath, src);
    });

  };

  //--------------------------------------------------------------------------------------------------------------------
  // PRIVATE
  //--------------------------------------------------------------------------------------------------------------------

  /**
   * Scans a stylesheet for asset URL references and copies the assets to the build folder.
   * @private
   * @param {string} basePath
   * @param {string} targetPath
   * @param {string} sourceCode
   */
  function scan (basePath, targetPath, sourceCode)
  {
    var match;
    while ((match = MATCH_URLS.exec (sourceCode))) {
      var url = match[2];
      if (!url.match (/^http/i) && url[0] !== '/') { // Skip absolute URLs
        var absSrcPath = path.resolve (basePath, url)
          , absDestPath = path.resolve (targetPath, options.targetDir, url)
          , relDestPath = path.relative (targetPath, absDestPath);
        if (relDestPath[0] === '.')
          return util.warn ('Relative asset url falls outside the build folder: <cyan>%</cyan>%', url, util.NL);
        if (exportedAssets[absDestPath]) // skip already exported asset
          continue;
        else exportedAssets[absDestPath] = true;
        var absTargetFolder = path.dirname (absDestPath);
        grunt.file.mkdir (absTargetFolder);
        if (options.symlink)
          fs.symlinkSync (absSrcPath, absDestPath);
        else grunt.file.copy (absSrcPath, absDestPath);
      }
    }
  }

}
1062454
function( path, callback ) {
		var match = munit.isRegExp( render.options.file_match ) ? render.options.file_match : rtestfile;

		path += '/';
		fs.readdir( path, function( e, files ) {
			if ( e ) {
				return callback( e );
			}

			async.each( files || [],
				function( file, callback ) {
					var fullpath = path + file;

					fs.stat( fullpath, function( e, stat ) {
						if ( e ) {
							callback( e );
						}
						else if ( stat.isDirectory() ) {
							render._renderPath( fullpath, callback );
						}
						else {
							if ( stat.isFile() && match.exec( file ) ) {
								munit.require( fullpath );
							}

							callback();
						}
					});
				},
				callback
			);
		});
	}
948814
function writeFile(cvs, data, callback) {
    if (typeof data.path !== 'string') {
      return callback(new TypeError('Invalid path type: ' + typeof data.path));
    }

    var fd, buff;

    // Write the buffer to the open file stream once both prerequisites are met.
    function writeBuffer() {
      fs.write(fd, buff, 0, buff.length, 0, function (error) {
        fs.close(fd);

        callback(error);
      });
    }

    // Create a buffer of the canvas' data.
    cvs.toBuffer(function (error, _buff) {
      if (error) return callback(error);

      buff = _buff;
      if (fd) {
        writeBuffer();
      }
    });

    // Open a stream for the file to be written.
    fs.open(data.path, 'w', WRITE_MODE, function (error, _fd) {
      if (error) return callback(error);

      fd = _fd;
      if (buff) {
        writeBuffer();
      }
    });
  }
975168
def export_image(self, bbox, zoomlevel, imagepath):
        
        assert has_pil, _("Cannot export image without python PIL")
        grid = self.grid_tiles(bbox, zoomlevel)
        width = len(grid[0])
        height = len(grid)
        widthpix = width * self.tile_size
        heightpix = height * self.tile_size

        result = Image.new("RGBA", (widthpix, heightpix))
        offset = (0, 0)
        for i, row in enumerate(grid):
            for j, (x, y) in enumerate(row):
                offset = (j * self.tile_size, i * self.tile_size)
                img = self._tile_image(self.tile((zoomlevel, x, y)))
                result.paste(img, offset)
        logger.info(_("Save resulting image to '%s'") % imagepath)
        result.save(imagepath)
1081649
@SuppressWarnings("deprecated")
	protected String getDownloadPath(BufferedImage chartImage)
			throws IOException
	{
		File imageOutputFile = ExportDownload.createTempFile("chart", ".png");

		ImageIO.write(chartImage, "png", imageOutputFile);

		return ExportDownload.getUrl(imageOutputFile, "image/png");
	}
45318
function (file) {
                var _this = this;
                return new Promise(function (resolve, reject) {
                    return __awaiter(_this, void 0, void 0, function () {
                        var imageSrc, err_3, img;
                        var _this = this;
                        return __generator(this, function (_a) {
                            switch (_a.label) {
                                case 0:
                                    _a.trys.push([0, 2, , 3]);
                                    return [4 /*yield*/, readFile()];
                                case 1:
                                    imageSrc = _a.sent();
                                    return [3 /*break*/, 3];
                                case 2:
                                    err_3 = _a.sent();
                                    reject(err_3);
                                    return [3 /*break*/, 3];
                                case 3:
                                    img = new Image();
                                    img.onload = function () {
                                        return __awaiter(_this, void 0, void 0, function () {
                                            var ctx, width, _a;
                                            return __generator(this, function (_b) {
                                                switch (_b.label) {
                                                    case 0:
                                                        // set edited image canvas and dimensions
                                                        this.editedImage = ( /** @type {?} */(document.createElement('canvas')));
                                                        this.editedImage.width = img.width;
                                                        this.editedImage.height = img.height;
                                                        ctx = this.editedImage.getContext('2d');
                                                        ctx.drawImage(img, 0, 0);
                                                        // resize image if larger than max image size
                                                        width = img.width > img.height ? img.height : img.width;
                                                        if (!(width > this.options.maxImageDimensions.width))
                                                            return [3 /*break*/, 2];
                                                        _a = this;
                                                        return [4 /*yield*/, this.resize(this.editedImage)];
                                                    case 1:
                                                        _a.editedImage = _b.sent();
                                                        _b.label = 2;
                                                    case 2:
                                                        this.imageDimensions.width = this.editedImage.width;
                                                        this.imageDimensions.height = this.editedImage.height;
                                                        this.setPreviewPaneDimensions(this.editedImage);
                                                        resolve();
                                                        return [2 /*return*/];
                                                }
                                            });
                                        });
                                    };
                                    img.src = imageSrc;
                                    return [2 /*return*/];
                            }
                        });
                    });
                });
                /**
                 * read file from input field
                 * @return {?}
                 */
                function readFile() {
                    return new Promise(function (resolve, reject) {
                        /** @type {?} */
                        var reader = new FileReader();
                        reader.onload = function (event) {
                            resolve(reader.result);
                        };
                        reader.onerror = function (err) {
                            reject(err);
                        };
                        reader.readAsDataURL(file);
                    });
                }
            }
1018453
function (format) {
        if (!this.image || !this.size) return null;

        format = format || "image/png";
        var canvas = document.createElement("canvas");
        var context = canvas.getContext("2d");
        context.canvas.width = this.size.w;
        context.canvas.height = this.size.h;

        var imgData = context.createImageData(this.size.w, this.size.h);
        for (var i = 0; i < this.image.length; i++) {
            imgData.data[i] = this.image[i];
        }
        context.putImageData(imgData, 0, 0);
        
        return canvas.toDataURL(format);
    }
232268
function(callback) {
      var firstThumbnail;

      for (var i = 0; i < thumbnailsPaths.length; i++) {
        var thumbnailsPath = thumbnailsPaths[i].thumbnailPath;

        if (!firstThumbnail)
          firstThumbnail = gm(thumbnailsPath);
        else
          firstThumbnail.append(thumbnailsPath, horizontally);

        images.push({
          sprite: destinationPath,
          image: thumbnailsPaths[i].originalPath,
          x: horizontally ? width * i : 0,
          y: horizontally ? 0 : height * i
        });
      }
      firstThumbnail
        .quality(quality)
        .write(destinationPath, callback);
    }