Skip to content

Instantly share code, notes, and snippets.

@Cifro
Created January 30, 2011 15:07
Show Gist options
  • Save Cifro/802922 to your computer and use it in GitHub Desktop.
Save Cifro/802922 to your computer and use it in GitHub Desktop.
PNG -> DataURI in LESS syntax
<title>PNG -&gt; DataURI in LESS syntax</title>
<form method=post>
<input type="text" size="150" name="folder">
<input type="submit" value="Go">
</form>
<pre>
<?php
// save output to e.g. icons.less
// and in main file add:
// @import "icons.less";
if(isset($_POST['folder'])){
$folder = $_POST['folder'];
foreach(glob("$folder/*.png") as $file){
$f = file_get_contents($file);
$file = preg_replace("/(-\d+)/", "", $file);
echo "@" . strtolower(basename($file, '.png')) . '-icon: "data:image/png;base64,' . base64_encode($f) . '";' . "\n";
}
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment