Skip to content

Instantly share code, notes, and snippets.

@unwiredben
Forked from 140bytes/LICENSE.txt
Created September 18, 2011 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unwiredben/1225322 to your computer and use it in GitHub Desktop.
Save unwiredben/1225322 to your computer and use it in GitHub Desktop.
140byt.es -- squareImg

squareImg

This is an img tag loader that resizes the image to fix into a square area, using CSS to provide padding on the sides to keep the original aspect ratio. This solves the problem of using an tag with a square width/height

Use like

squareImg("http://url/to/image", 128, "#000000", function(i) { /* image loaded into DOM node i, ready to insert into my own DOM */ });
function(){
// make sure
// to annotate
// your code
// so everyone
// can learn
// from it!
// see jed's entries
// for examples.
}
function(){/* Your entry, a useful, unique, and valid JavaScript expression that packs as much functionality into 140 bytes as possible. */}
DO WHAT THE F*** YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Ben Combee <combee@techwood.org>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE F*** YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE F*** YOU WANT TO.
{
"name": "squareImg",
"description": "This should be a short description of your entry.",
"keywords": [
"image",
"loader",
"dom"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>undefined</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function(){ /* the code here should be identical to the entry. */ }
document.getElementById( "ret" ).innerHTML = myFunction()
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment