ImageData can't be cloned or deep-copied, it's an internal data structure and has some CRAZY crap in it, this is cheeeeeezy, but hey, it works, and it's portable!!!
489679
public final ImageData copy()
    {
        final Context2D context = new ScratchPad(getWidth(), getHeight()).getContext();

        context.putImageData(this, 0, 0);

        return context.getImageData(0, 0, getWidth(), getHeight());
    }
248997
function copyData (dest, sourceData) {
  var parsedProperty;
  var key;
  for (key in sourceData) {
    if (sourceData[key] === undefined) { continue; }
    parsedProperty = sourceData[key];
    dest[key] = isObjectOrArray(parsedProperty)
      ? utils.clone(parsedProperty)
      : parsedProperty;
  }
  return dest;
}
316038
def _image_to_data(img):
    
    # If the image is already encoded in Base64, we have nothing to do here
    if "src" not in img.attrs or img["src"].startswith("data:"):
        return
    elif re.match("https?://", img["src"]):
        img_data = _load_url(img["src"]).read()
    else:
        img_data = _load_file(img["src"]).read()
    img_type = imghdr.what("", img_data)
    img_b64 = base64.b64encode(img_data)
    src_data = "data:image/none;base64,"
    if img_type:
        src_data = "data:image/{};base64,{}".format(img_type, img_b64)
    img["src"] = src_data
497168
function imagetransfer($src_im, $dst_im) {
        if (is_resource($dst_im)) imagedestroy($dst_im);
        $dst_im = & $src_im;
        return $dst_im;
    }
332018
function encode(data) {
	const bytes = buffer.Buffer.from(data, 'utf8');
	const pixelData = prependLength(bytes);

	return createPng(pixelData);
}
56909
def _write_single_batch_images_internal(self, batch_id, client_batch):
    """"""
    client = self._datastore_client
    batch_key = client.key(self._entity_kind_batches, batch_id)
    for img_id, img in iteritems(self._data[batch_id]['images']):
      img_entity = client.entity(
          client.key(self._entity_kind_images, img_id, parent=batch_key))
      for k, v in iteritems(img):
        img_entity[k] = v
      client_batch.put(img_entity)
1317877
function (image, old) {
        var data1 = old.data,
            data2 = image.data,
            w1 = old.width,
            w2 = image.width,
            px1 = old.globalOffset.x,
            py1 = old.globalOffset.y,
            px2 = image.globalOffset.x,
            py2 = image.globalOffset.y,
            b1 = old.bounds,
            b2 = image.bounds,
            px = Math.min(b1.minX + px1, b2.minX + px2), // global offset for new image (by min in bounds)
            py = Math.min(b1.minY + py1, b2.minY + py2),
            b = { // bounds for new image include all of the pixels [0,0,width,height] (reduce to bounds)
                minX: 0,
                minY: 0,
                maxX: Math.max(b1.maxX + px1, b2.maxX + px2) - px,
                maxY: Math.max(b1.maxY + py1, b2.maxY + py2) - py,
            },
            w = b.maxX + 1, // size for new image
            h = b.maxY + 1,
            i, j, k, k1, k2, len;

        var result = new Uint8Array(w * h);

        // copy all old image
        len = b1.maxX - b1.minX + 1;
        i = (py1 - py + b1.minY) * w + (px1 - px + b1.minX);
        k1 = b1.minY * w1 + b1.minX;
        k2 = b1.maxY * w1 + b1.minX + 1;
        // walk through rows (Y)
        for (k = k1; k < k2; k += w1) {
            result.set(data1.subarray(k, k + len), i); // copy row
            i += w;
        }

        // copy new image (only "black" pixels)
        len = b2.maxX - b2.minX + 1;
        i = (py2 - py + b2.minY) * w + (px2 - px + b2.minX);
        k1 = b2.minY * w2 + b2.minX;
        k2 = b2.maxY * w2 + b2.minX + 1;
        // walk through rows (Y)
        for (k = k1; k < k2; k += w2) {
            // walk through cols (X)
            for (j = 0; j < len; j++) {
                if (data2[k + j] === 1) result[i + j] = 1;
            }
            i += w;
        }

        return {
            data: result,
            width: w,
            height: h,
            bounds: b,
            globalOffset: {
                x: px,
                y: py,
            }
        };
    }
1313891
public static boolean canWrite (BufferedImage image)
    {
        return (image.getColorModel() instanceof IndexColorModel) &&
            (image.getRaster().getDataBuffer() instanceof DataBufferByte);
    }
1171057
def to_uint8(self, data):
        
        np = util.get_module(
            "numpy", required="wandb.Image requires numpy if not supplying PIL Images: pip install numpy")

        # I think it's better to check the image range vs the data type, since many
        # image libraries will return floats between 0 and 255

        # some images have range -1...1 or 0-1
        dmin = np.min(data)
        if dmin < 0:
            data = (data - np.min(data)) / np.ptp(data)
        if np.max(data) <= 1.0:
            data = (data * 255).astype(np.int32)

        #assert issubclass(data.dtype.type, np.integer), 'Illegal image format.'
        return data.clip(0, 255).astype(np.uint8)
984453
private int imageDataSize()
    {
		int size = 0;
    	for(int k = 0; k < imageData.length; k++) {
    		size += imageData[k].length;
    	}   
    	return size;
    }
434176
function deepCopy(obj) {
	var res;
	var i;
	var key;
	if (isTerminal(obj)) {
		res = obj;
	} else if (Array.isArray(obj)) {
		res = Array(obj.length);
		for (i = 0; i < obj.length; i++) {
			res[i] = deepCopy(obj[i]);
		}
	} else {
		res = {};
		for (key in obj) {
			res[key] = deepCopy(obj[key]);
		}
	}
	return res;
}
798125
function storedPixelDataToImageData (image) {
  const minPixelValue = image.minPixelValue;
  let canvasImageDataIndex = 0;
  let storedPixelDataIndex = 0;
  // Only 3 channels, since we use WebGL's RGB texture format
  const numStoredPixels = image.width * image.height * 4;
  const numOutputPixels = image.width * image.height * 3;
  const storedPixelData = image.getPixelData();
  const data = new Uint8Array(numOutputPixels);

  // NOTE: As of Nov 2014, most javascript engines have lower performance when indexing negative indexes.
  // We have a special code path for this case that improves performance.  Thanks to @jpambrun for this enhancement
  if (minPixelValue < 0) {
    while (storedPixelDataIndex < numStoredPixels) {
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++] + (-minPixelValue); // Red
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++] + (-minPixelValue); // Green
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++] + (-minPixelValue); // Blue
      storedPixelDataIndex += 1; // The stored pixel data has 4 channels
    }
  } else {
    while (storedPixelDataIndex < numStoredPixels) {
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++]; // Red
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++]; // Green
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++]; // Blue
      storedPixelDataIndex += 1; // The stored pixel data has 4 channels
    }
  }

  return data;
}
1163298
function(data) {

		return data instanceof Object && (
		(this.domInstance('input', data) && data.type === 'file') ||
		('FileList' in window && data instanceof window.FileList) ||
		('File' in window && data instanceof window.File) ||
		('Blob' in window && data instanceof window.Blob));

	}
405902
function _imageCopyResampledWorkaround(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
    {
        /*
        for ($i = 0; $i < imagecolorstotal($src_img); $i++)
        {
            $colors = ImageColorsForIndex ($src_img, $i);
            ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
        }
        */
        $scaleX = ($src_w - 1) / $dst_w;
        $scaleY = ($src_h - 1) / $dst_h;

        $scaleX2 = $scaleX / 2.0;
        $scaleY2 = $scaleY / 2.0;

        for ($j = $src_y; $j < $src_y + $dst_h; $j++)
        {
            $sY = $j * $scaleY;
            for ($i = $src_x; $i < $src_x + $dst_w; $i++)
            {
                $sX = $i * $scaleX;

                $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY + $scaleY2));
                $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY));
                $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY + $scaleY2));
                $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY));

                $red = (integer)(($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
                $green = (integer)(($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
                $blue = (integer)(($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);

                $color = ImageColorClosest($dst_img, $red, $green, $blue);
                ImageSetPixel($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y, $color);
            }
        }
    }
1032902
function isDataSource( image ) {

    const source = (typeof image === "string" ? image : image.src).substr(0, 5);

    // base 64 string contains data-attribute, the MIME type and then the content, e.g. :
    // e.g. "data:image/png;base64," for a typical PNG, Blob string contains no MIME, e.g.:
    // blob:http://localhost:9001/46cc7e56-cf2a-7540-b515-1d99dfcb2ad6
    return source === "data:" || source === "blob:";
}
160147
function clone(orig, dataType){
	if(!dataType)
		dataType = getDataType(orig);

	if(dataType == 'Array'){
		var newArray = [];
		for(var i = 0; i < orig.length; i++)
			newArray.push(orig[i]);

		return newArray;

	} else if(dataType == 'Object') {
		var newObject = {};
		for(var key in orig)
			newObject[key] = clone(orig[key]);

		return newObject;

	} else
		return orig;
}
52083
function(dataURI) {
        var binary = atob(dataURI.split(',')[1]);
        var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
        var array = [];

        for(var i = 0; i < binary.length; i++) {
          array.push(binary.charCodeAt(i));
        }

        return new Blob([ new Uint8Array(array) ], { type: mimeString });
      }