Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                new<!-- http://strd6.com/2011/09/html5-javascript-pasting-image-data-in-chrome/ -->

<div class="container fluid">
	<div class="row">
		<h1>HTML5 paste image to page</h1>
		<blockquote>Did you know that <code>HTML5</code> lets the user paste an image into the DOM tree? See a demo here and find the code needed in this <a href="https://gist.github.com/STRd6/5286415">Gist</a>. I first came across this code here in a post <a href="http://strd6.com/2011/09/html5-javascript-pasting-image-data-in-chrome/">HTML5 JavaScript Pasting Image Data in Chrome</a>			by <a href="http://strd6.com/author/yahivin/">Daniel X Moore</a> (from 2011!).</blockquote>
		<strong>Instructions</strong>: Copy an image to clipboard (For instance: <strong>Mac</strong>: <code>cmd+shift+ctrl+4</code> and <strong>Win</strong>: <code>Alt+PtrScr</code>), click on the <i>target div</i> to paste the image into, and paste <code>cmd+V</code>		or <code>ctrl+v</code>. <br />
		<strong class="text-info">Version 1.1</strong> Added camera snapshoot sound on paste - use my pen <a href="https://codepen.io/netsi1964/pen/IHwco">Snapshoot sound - snapshoot()
</a> to get that feature on your pens. Also added option to toggle <code>background-size: contain</code> when clicking on pasted image.
	</div>
	<div class="row">
		<div class="span4 target"></div>
		<div class="span4 target"></div>
		<div class="span4 target"></div>
	</div>
	<div class="row">

		<div class="span12">
			<br />
			<div class="input-prepend">
				<span class="add-on">size</span>
				<input class="span2 size" id="size" type="text" placeholder="size of pasted image">
			</div>

			<div class="input-prepend">
				<span class="add-on">type</span>
				<input class="span2 type" id="type" type="text" placeholder="Image type pasted">
			</div>

			<div class="input-prepend">
				<span class="add-on">width</span>
				<input class="span2 type" id="width" type="text" placeholder="Width">
			</div>

			<div class="input-prepend">
				<span class="add-on">height</span>
				<input class="span2 type" id="height" type="text" placeholder="Height">
			</div>
		</div>
		<div class="span12">
			<legend>The dataURL of the image <a href="#" onclick="copy()">copy to clipboard</a>. Copy as <a href="#" onclick="copyMDImage()" class="new">Markdown image link</a></legend>
			<textarea id="base64" cols="30" rows="10" class="data span12"></textarea></div>
	</div>

</div>

<textarea style="position: absolute; top: 10px;z-index: 1000; left: -10000px;" id="base64MD" cols="30" rows="10"></textarea>
              
            
!

CSS

              
                .target {
  border: solid 1px #aaa;
  min-height: 200px;
  width: 30%;
  margin-top: 1em;
  border-radius: 5px;
  cursor: pointer;
  transition: 300ms all;
  position: relative;
}

.contain {
    background-size: cover;
  position: relative;
  z-index: 10;
  top: 0px;
  left: 0px;
}
textarea {
  background-color: white;
}
.active {
  box-shadow: 0px 0px 10px 10px rgba(0,0,255,.4);
}


.new:after {
	content: "NEW feature";
	color: white;
	letter-spacing: 1px;
	background: hsla(80, 90%, 40%, .9);
	position: absolute;
	margin: -10px 5px 0 0;
	transform: rotate(-25deg);
	padding: 2px 5px;
	border-radius: 4px;
	font-size: 10px;
	line-height: 14px;
	opacity: .85;
}
              
            
!

JS

              
                // Created by STRd6
// MIT License
// jquery.paste_image_reader.js
(function($) {
	var defaults;
	$.event.fix = (function(originalFix) {
		return function(event) {
			event = originalFix.apply(this, arguments);
			if (event.type.indexOf("copy") === 0 || event.type.indexOf("paste") === 0) {
				event.clipboardData = event.originalEvent.clipboardData;
			}
			return event;
		};
	})($.event.fix);
	defaults = {
		callback: $.noop,
		matchType: /image.*/
	};
	return ($.fn.pasteImageReader = function(options) {
		if (typeof options === "function") {
			options = {
				callback: options
			};
		}
		options = $.extend({}, defaults, options);
		return this.each(function() {
			var $this, element;
			element = this;
			$this = $(this);
			return $this.bind("paste", function(event) {
				var clipboardData, found;
				found = false;
				clipboardData = event.clipboardData;
				return Array.prototype.forEach.call(clipboardData.types, function(type, i) {
					var file, reader;
					if (found) {
						return;
					}
					if (
						type.match(options.matchType) ||
						clipboardData.items[i].type.match(options.matchType)
					) {
						file = clipboardData.items[i].getAsFile();
						reader = new FileReader();
						reader.onload = function(evt) {
							return options.callback.call(element, {
								dataURL: evt.target.result,
								event: evt,
								file: file,
								name: file.name
							});
						};
						reader.readAsDataURL(file);
						setTimeout(() => {
						var t = document.getElementById("base64");
						var md = document.getElementById('base64MD');
						md.value = `![image](${t.value})`;	
						}, 1000)
						
						snapshoot();
						return (found = true);
					}
				});
			});
		});
	});
})(jQuery);

var dataURL, filename;
$("html").pasteImageReader(function(results) {
	filename = results.filename, dataURL = results.dataURL;
	$data.text(dataURL);
	$size.val(results.file.size);
	$type.val(results.file.type);
	var img = document.createElement("img");
	img.src = dataURL;
	var w = img.width;
	var h = img.height;
	$width.val(w);
	$height.val(h);
	return $(".active")
		.css({
			backgroundImage: "url(" + dataURL + ")"
		})
		.data({ width: w, height: h });
});

var $data, $size, $type, $width, $height;
$(function() {
	$data = $(".data");
	$size = $(".size");
	$type = $(".type");
	$width = $("#width");
	$height = $("#height");
	$(".target").on("click", function() {
		var $this = $(this);
		var bi = $this.css("background-image");
		if (bi != "none") {
			$data.text(bi.substr(4, bi.length - 6));
		}

		$(".active").removeClass("active");
		$this.addClass("active");

		$this.toggleClass("contain");

		$width.val($this.data("width"));
		$height.val($this.data("height"));
		if ($this.hasClass("contain")) {
			$this.css({
				width: $this.data("width"),
				height: $this.data("height"),
				"z-index": "10"
			});
		} else {
			$this.css({ width: "", height: "", "z-index": "" });
		}
	});
});

function copy(text) {
	var t = document.getElementById("base64");
	t.select();
	try {
		var successful = document.execCommand("copy");
		var msg = successful ? "successfully" : "unsuccessfully";
		alert("Base64 data coppied " + msg + " to clipboard");
	} catch (err) {
		alert("Unable to copy text");
	}
}


function copyMDImage() {
	var md = document.getElementById('base64MD');
	md.select();
	try {
		var successful = document.execCommand("copy");
		var msg = successful ? "successfully" : "unsuccessfully";
		alert("Markdown Base64 data coppied " + msg + " to clipboard");
	} catch (err) {
		alert("Unable to copy text");
	}
}
              
            
!
999px

Console