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


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


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.


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.

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.


                <a href='javascript:(function(){var t;t=function(){function t(){}return{return this.getImages(),this.buildCanvas(),this.process(),this.clean()},t.prototype.getImages=function(){return this.images=document.getElementsByTagName("img")},t.prototype.buildCanvas=function(){return this.canvas=document.createElement("canvas"),this.stage=this.canvas.getContext("2d"),document.body.appendChild(this.canvas),this.resizeCanvas(1,1)},t.prototype.resizeCanvas=function(t,e){return this.canvas.setAttribute("style","width: "+t+"px; height: "+e+"px; position: fixed; opacity: 0; left: -"+t+"px; top: -"+e+"px;"),this.canvas.setAttribute("width",t),this.canvas.setAttribute("height",e)},t.prototype.process=function(){var t,e,i,a,s,n;for(s=this.images,n=[],i=0,a=s.length;a>i;i++){e=s[i];try{this.image=e,this.allow(),this.setScale(),this.getImageData(),this.glitchData(),n.push(this.setData())}catch(r){t=r,n.push(console.log(t))}}return n},t.prototype.allow=function(){return this.image.setAttribute("crossOrigin","anonymous")},t.prototype.setScale=function(){var t,e;return e=this.image.offsetWidth,t=this.image.offsetHeight,this.resizeCanvas(e,t)},t.prototype.getImageData=function(){return this.stage.drawImage(this.image,0,0),"image/jpeg")},t.prototype.glitchData=function(){var t,e,i,a,s;for(,",")+1),",")+1),t=0,i=1+Math.floor(10*Math.random());i>t;)a=Math.round(Math.random()*e.length-1),e=e.substr(0,a)+e.charAt(a+1)+e.charAt(a)+e.substr(a+2),t++;return},t.prototype.setData=function(){var t;return t=document.createElement("img"),t.setAttribute("width",this.image.offsetWidth),t.setAttribute("height",this.image.offsetHeight),t.setAttribute("src",,document.body.insertBefore(t,this.image),this.image.parentNode.removeChild(this.image)},t.prototype.clean=function(){return this.canvas.parentNode.removeChild(this.canvas),this.image=null,},t}(),window.glitch=new t,}).call(this);' class="bookmarklet">Glitch</a>
<p>Drag the button above into your bookmarks, open any image in a new tab, and then click the bookmark to glitch the image.<br /><span>(Right click on the background image and open it in a new tab to try it out.)</span></p>
<img src="" />


                @import compass

html , body
  overflow: hidden
  position: absolute
  height: 100%
  width: 100%
  left: 0
  top: 0

  background-image: url( )
  background-position: left center
  background-size: cover
  background-color: rgba( 0 , 0 , 0 , 0.3 )
  position: absolute
  opacity: 0
  width: 100%
  height: 100%
  left: 0
  top: 0

p , .bookmarklet
  text-shadow: 0 0 15px rgba( 0, 0, 0, 0.4 )
  font-weight: 100
  letter-spacing: 0.05em
  font-family: sans-serif
  text-align: center
  position: absolute
  z-index: 2
  color: white
  left: 50%
  top: 50%
  @include translate( -50% , 0 )
  width: 400px
  line-height: 18px
  font-size: 15px
  margin-top: 80px
    display: block
    margin: 50px
    width: 300px
    font-size: 11px
    line-height: 14px

  @include translate( -50% , -50% )
  cursor: -webkit-grab
  cursor: grab
  margin: -3px 0 0 -3px
  box-shadow: 5px 5px 0 0 white
  font-size: 21px
  text-decoration: none
  background-color: red
  padding: 15px
    cursor: -webkit-grabbing
    cursor: grabbing


                # here's the source for anyone that's interested
class Glitch

	# call this to run the script,
	# ``
	run: ->
		# find all the images

		# make a canvas to edit them

		# actually glitch the images

		# remove extra dom elements once finished

	getImages: ->

		# store all image elements to this class
		@.images = document.getElementsByTagName "img"

	buildCanvas: ->

		# make the canvas element
		@.canvas = document.createElement "canvas"

		# get the context for printing image data
		@.stage = @.canvas.getContext "2d"

		# add the canvas to the dom
		document.body.appendChild @.canvas

		# set its inital style
		@.resizeCanvas 1 , 1

	resizeCanvas: ( w , h ) ->

		# set the style attributes for it
		@.canvas.setAttribute "style" , "width: #{w}px; height: #{h}px; position: fixed; opacity: 0; left: -#{w}px; top: -#{h}px;"

		# also set the element attributes
		@.canvas.setAttribute "width" , w
		@.canvas.setAttribute "height" , h

	process: ->

		# loop through each image
		for image in @.images

			# wrap this in a try/catch so security issues don't break it

				# store the image so we can edit it
				@.image = image

				# security hack?

				# rescale the canvas

				# put the image on the canvas so we can get its image data

				# glitch the data uri

				# put the image data back into the image element

			catch error

				# log the error for those interested
				console.log error

	allow: ->

		@.image.setAttribute "crossOrigin" , "anonymous"

	setScale: ->

		# get the image size
		w = @.image.offsetWidth
		h = @.image.offsetHeight

		# scale the canvas
		@.resizeCanvas w , h

	getImageData: ->

		# draw the image onto the canvas
		@.stage.drawImage @.image , 0 , 0

		# get the image data = @.canvas.toDataURL "image/jpeg"

	glitchData: ->

		# get the part of the string that can be glitched and the prefix
		prefix = 0 , "," ) + 1 )
		image =",") + 1 )

		# run for a random number of iterations
		i = 0
		p = 1 + Math.floor( Math.random() * 10 )
		while i < p

			# find the point we split at
			point = Math.round( Math.random() * image.length - 1 )

			# rejoin and save it
			image = image.substr( 0 , point ) + image.charAt( point + 1 ) + image.charAt( point ) + image.substr( point + 2 )


		# store the data again = prefix + image

	setData: ->

		# make a new element to place it into
		img = document.createElement "img"

		# get the original scale
		img.setAttribute "width" , @.image.offsetWidth
		img.setAttribute "height" , @.image.offsetHeight

		# apply the source
		img.setAttribute "src" ,

		# append the new image and remove the old
		document.body.insertBefore img , @.image
		@.image.parentNode.removeChild @.image

	clean: ->

		# destroy the canvas element
		@.canvas.parentNode.removeChild @.canvas

		# stop referencing the last image
		@.image = null

		# clear image data from class = null

window.glitch = new Glitch