css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <label for="path">Path to favicons</label>
<input id="path" placeholder="enter the path to your favicons & browserconfig.xml"><br>
<label for="path">Windows Tile background color</label>
<input class="jscolor" value="2b5797"><br>
<label>PNG Image (228 x 228 or larger)</label>
<input type="file" id="select">
<img id="preview">
<br>
<p>Images must be square :)</p>

<h1>HTML</h1>
<p>Place the Following in the &lt;head&gt;&lt;/head&gt; of your HTML</p>
<code id="html">
&lt;!-- generics --&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-32.png" sizes="32x32"&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-57.png" sizes="57x57"&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-76.png" sizes="76x76"&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-96.png" sizes="96x96"&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-128.png" sizes="128x128"&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-192.png" sizes="192x192"&gt;<br />
&lt;link rel="icon" href="<span>/path/to</span>/favicon-228.png" sizes="228x228"&gt;<br />
<br />
&lt;!-- Android --&gt;<br />
&lt;link rel="shortcut icon" sizes="196x196" href=“<span>/path/to</span>/favicon-196.png"&gt;<br />
<br />
&lt;!-- iOS --&gt;<br />
&lt;link rel="apple-touch-icon" href="<span>/path/to</span>/favicon-120.png" sizes="120x120"&gt;<br />
&lt;link rel="apple-touch-icon" href="path/to/favicon-152.png" sizes="152x152"&gt;<br />
&lt;link rel="apple-touch-icon" href="path/to/favicon-180.png" sizes="180x180"&gt;<br />
<br />
&lt;!-- Windows 8  IE 10--&gt;<br />
&lt;meta name="msapplication-TileColor" content="#<output>FFFFFF</output>"&gt;<br />
&lt;meta name="msapplication-TileImage" content="<span>/path/to</span>/favicon-144.png"&gt;<br />
<br />
&lt;!— Windows 8.1 + IE11 and above —&gt;<br />
&lt;meta name="msapplication-config" content="<span>/path/to</span>/browserconfig.xml" /&gt;<br />
</code>
<br>
<button id="saveFileHTML">Save File</button>


<h1>browserconfig.xml</h1>

<code id="xml">
&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;browserconfig&gt;<br />
  &lt;msapplication&gt;<br />
    &lt;tile&gt;<br />
      &lt;square70x70logo src=“favicon-76.png”/&gt;<br />
      &lt;square150x150logo src="favicon-228.png"/&gt;<br />
	&lt;TileColor&gt;#<span>2b5797</span>&lt;/TileColor&gt;<br />
    &lt;/tile&gt;<br />
  &lt;/msapplication&gt;<br />
&lt;/browserconfig&gt;
</code>
<br>
<button id="saveFileBROWSER">Save File</button>
<br>
<h1>Favicons</h1>
<img id="favicon-228.png" class="preview" data-size="228"><br>
<img id="favicon-196.png" class="preview" data-size="196"><br>
<img id="favicon-180.png" class="preview" data-size="180"><br>
<img id="favicon-144.png" class="preview" data-size="144"><br>
<img id="favicon-128.png" class="preview" data-size="128"><br>
<img id="favicon-96.png"  class="preview" data-size="96"><br>
<img id="favicon-76.png"  class="preview" data-size="76"><br>
<img id="favicon-57.png"  class="preview" data-size="57"><br>
<img id="favicon-32.png"  class="preview" data-size="32"><br>
<button id="saveFavIcons">Save File</button>

<h3>Windows tile preview</h3>
<div id="smalltile"><img class="preview" data-size="70"></div>
<div id="mediumtile"><img class="preview" data-size="150"></div>


            
          
!
            
              body {
	padding: 10px;
}
#path {
	min-width: 400px;
}
label {
	display:inline-block;
	min-width: 250px;
}
#smalltile, #mediumtile {
	background: #2B5797;
	display: flex;
  justify-content: center;
  align-items: center;
}
#smalltile {
	width: 70px;
	height: 70px;
	margin-bottom: 30px;
		img {
			width: 40px;
		}
}
#mediumtile {
	width: 150px;
	height: 150px;
		img {
			width: 70px;
		}
}
            
          
!
            
              // Simple JQuery for inputs
$( "#path" ).change(function() {
    var inputval = $( this ).val();
		$("#html span").html(inputval); //update code
});
$( ".jscolor" ).change(function() {
    var inputval2 = $( this ).val();
		$("#xml span").html(inputval2) //update code
		$("#html output").html(inputval2) //update code
});
// Click Handlers
$( "#saveFileHTML" ).click(function() {
  saveToDiskText("#html", "head.html");
});
$( "#saveFileBROWSER" ).click(function() {
  saveToDiskText("#xml","browserconfig.xml");
});


$( "#saveFavIcons" ).click(function() {
	$( ".preview" ).each(function() {
		var dataSize = $(this).attr("data-size");
		var filename = "favicon-" + dataSize + ".png";
		saveToDiskImage(this, filename);
	});
});




// save file FileSaver.js
function saveToDiskText (target, filename){
	var filebody = $(target).text();
	var file = new File([filebody], filename, {type: "text/plain;charset=utf-8"});
	saveAs(file);
}
//save file image js
function saveToDiskImage (target, filename){
	var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
// draw to canvas...
	canvas.toBlob(function(blob) {
			saveAs(blob, filename);
	});
}


function resize(size, target) {
	var file = $("#select")[0].files[0];
	console.log("this is my file " + file);
	console.log("this is my target " + target);

		ImageTools.resize( file, {
        width: size, // maximum width
        height: size // maximum height
    }, function(blob, didItResize) {
        // didItResize will be true if it managed to resize it, otherwise false (and will return the original file as 'blob')
				var src = window.URL.createObjectURL(blob);
        $(target).attr("src", src) 
        // you can also now upload this blob using an XHR.
    });
}



$("#select").change(function() {
	 //resize(320,);
	$( ".preview" ).each(function() {
		
		//var size = $(this).data(size);
		var size = $(this).attr("data-size")
		console.log(size);
		resize(size, this);
	});
})

									 
									 

// http://stackoverflow.com/questions/2434458/image-resizing-client-side-with-javascript-before-upload-to-the-server
// https://github.com/eligrey/FileSaver.js









'use strict';
if (typeof exports === "undefined") {
    var exports = {};
}

if (typeof module === "undefined") {
   var module = {};
}

Object.defineProperty(exports, '__esModule', {
    value: true
});

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var hasBlobConstructor = typeof Blob !== 'undefined' && (function () {
    try {
        return Boolean(new Blob());
    } catch (e) {
        return false;
    }
})();

var hasArrayBufferViewSupport = hasBlobConstructor && typeof Uint8Array !== 'undefined' && (function () {
    try {
        return new Blob([new Uint8Array(100)]).size === 100;
    } catch (e) {
        return false;
    }
})();

var hasToBlobSupport = typeof HTMLCanvasElement !== "undefined" ? HTMLCanvasElement.prototype.toBlob : false;

var hasBlobSupport = hasToBlobSupport || typeof Uint8Array !== 'undefined' && typeof ArrayBuffer !== 'undefined' && typeof atob !== 'undefined';

var hasReaderSupport = typeof FileReader !== 'undefined' || typeof URL !== 'undefined';

var ImageTools = (function () {
    function ImageTools() {
        _classCallCheck(this, ImageTools);
    }

    _createClass(ImageTools, null, [{
        key: 'resize',
        value: function resize(file, maxDimensions, callback) {
            if (typeof maxDimensions === 'function') {
                callback = maxDimensions;
                maxDimensions = {
                    width: 640,
                    height: 480
                };
            }

            var maxWidth = maxDimensions.width;
            var maxHeight = maxDimensions.height;

            if (!ImageTools.isSupported() || !file.type.match(/image.*/)) {
                callback(file, false);
                return false;
            }

            if (file.type.match(/image\/gif/)) {
                // Not attempting, could be an animated gif
                callback(file, false);
                // TODO: use https://github.com/antimatter15/whammy to convert gif to webm
                return false;
            }

            var image = document.createElement('img');

            image.onload = function (imgEvt) {
                var width = image.width;
                var height = image.height;
                var isTooLarge = false;

                if (width > height && width > maxDimensions.width) {
                    // width is the largest dimension, and it's too big.
                    height *= maxDimensions.width / width;
                    width = maxDimensions.width;
                    isTooLarge = true;
                } else if (height > maxDimensions.height) {
                    // either width wasn't over-size or height is the largest dimension
                    // and the height is over-size
                    width *= maxDimensions.height / height;
                    height = maxDimensions.height;
                    isTooLarge = true;
                }

                if (!isTooLarge) {
                    // early exit; no need to resize
                    callback(file, false);
                    return;
                }

                var canvas = document.createElement('canvas');
                canvas.width = width;
                canvas.height = height;

                var ctx = canvas.getContext('2d');
                ctx.drawImage(image, 0, 0, width, height);

                if (hasToBlobSupport) {
                    canvas.toBlob(function (blob) {
                        callback(blob, true);
                    }, file.type);
                } else {
                    var blob = ImageTools._toBlob(canvas, file.type);
                    callback(blob, true);
                }
            };
            ImageTools._loadImage(image, file);

            return true;
        }
    }, {
        key: '_toBlob',
        value: function _toBlob(canvas, type) {
            var dataURI = canvas.toDataURL(type);
            var dataURIParts = dataURI.split(',');
            var byteString = undefined;
            if (dataURIParts[0].indexOf('base64') >= 0) {
                // Convert base64 to raw binary data held in a string:
                byteString = atob(dataURIParts[1]);
            } else {
                // Convert base64/URLEncoded data component to raw binary data:
                byteString = decodeURIComponent(dataURIParts[1]);
            }
            var arrayBuffer = new ArrayBuffer(byteString.length);
            var intArray = new Uint8Array(arrayBuffer);

            for (var i = 0; i < byteString.length; i += 1) {
                intArray[i] = byteString.charCodeAt(i);
            }

            var mimeString = dataURIParts[0].split(':')[1].split(';')[0];
            var blob = null;

            if (hasBlobConstructor) {
                blob = new Blob([hasArrayBufferViewSupport ? intArray : arrayBuffer], { type: mimeString });
            } else {
                var bb = new BlobBuilder();
                bb.append(arrayBuffer);
                blob = bb.getBlob(mimeString);
            }

            return blob;
        }
    }, {
        key: '_loadImage',
        value: function _loadImage(image, file, callback) {
            if (typeof URL === 'undefined') {
                var reader = new FileReader();
                reader.onload = function (evt) {
                    image.src = evt.target.result;
                    if (callback) {
                        callback();
                    }
                };
                reader.readAsDataURL(file);
            } else {
                image.src = URL.createObjectURL(file);
                if (callback) {
                    callback();
                }
            }
        }
    }, {
        key: 'isSupported',
        value: function isSupported() {
            return typeof HTMLCanvasElement !== 'undefined' && hasBlobSupport && hasReaderSupport;
        }
    }]);

    return ImageTools;
})();

exports['default'] = ImageTools;
module.exports = exports['default'];
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console