Massive amount of changes. Now requires PHP for image uploading; front-end changes bring in uploader and some other fixes.

This commit is contained in:
Veno Server 2009-08-11 21:34:57 -05:00
parent f82d359803
commit 124af1d05c
5 changed files with 214 additions and 94 deletions

1
awesome/README Normal file
View file

@ -0,0 +1 @@
Forcing Git to recognize this folder, disregard.

View file

@ -20,7 +20,6 @@ html {
} }
body { body {
position: relative;
text-align: left; text-align: left;
width: 600px; width: 600px;
margin: 10px auto; margin: 10px auto;
@ -32,7 +31,30 @@ h1 {
color: #fff; color: #fff;
} }
#footer, #container_top, #container_bottom { #container_top { position: relative; }
#upload_button {
display: block;
width: 120px;
position: absolute;
top: 0;
right: 17px; /* Laziness */
padding: 5px;
background-color: #4FA36D;
color: #fff;
text-align: center;
font-size: 1em;
line-height: 1.2em;
-moz-border-radius-bottomleft: 4px;
-moz-border-radius-bottomright: 4px;
}
#upload_button:hover {
text-decoration: none;
background-color: #43895c;
}
#options, #footer, #container_top, #container_bottom {
background-color: #404d59; background-color: #404d59;
margin: 10px auto 5px; margin: 10px auto 5px;
text-align: left; text-align: left;
@ -41,11 +63,15 @@ h1 {
-webkit-border-radius: 6px; -webkit-border-radius: 6px;
-moz-border-radius: 6px; -moz-border-radius: 6px;
float: left; float: left;
clear: left;
} }
#container_bottom { display: none; } #container_bottom { display: none; }
#footer { text-align: center; margin-bottom: 30px; font-size: 1.2em; line-height: 1.4em; }
#footer { text-align: center; font-size: 1.2em; line-height: 1.4em; } #options { display: none; padding-top: 6px; }
#options a:first-child { margin-left: 66px; /* Huzzah for decent CSS support, but horrid CSS right here. :D */ }
a, a:visited { color: #f4d496; text-decoration: none; } a, a:visited { color: #f4d496; text-decoration: none; }
a:hover { text-decoration: underline; } a:hover { text-decoration: underline; }
@ -67,16 +93,16 @@ a:hover { text-decoration: underline; }
#interface { #interface {
float: right; float: right;
width: 460px; width: 460px;
margin-top: 23px; margin-top: 35px;
} }
#interface p { #uploader { display: none; }
#interface p, #hsv {
font: normal 1.2em/1.5em helvetica, sans-serif; font: normal 1.2em/1.5em helvetica, sans-serif;
padding: 4px 1px; padding: 4px 1px;
} }
#hsv a { margin-top: 4px; }
#img_input { #img_input {
border: 1px solid #c9c9c9; border: 1px solid #c9c9c9;
padding: 4px; padding: 4px;
@ -86,7 +112,7 @@ a:hover { text-decoration: underline; }
width: 370px; width: 370px;
} }
#img_submit, #hsv a { .img_submit, #hsv a {
border: 1px solid #55a2c9; border: 1px solid #55a2c9;
background-color: #498fb2; background-color: #498fb2;
color: #fff; color: #fff;
@ -94,15 +120,17 @@ a:hover { text-decoration: underline; }
-moz-border-radius: 4px; -moz-border-radius: 4px;
-webkit-border-radius: 4px; -webkit-border-radius: 4px;
} }
#hsv a { #hsv a {
display: block; display: block;
width: 104px; width: 120px;
padding: 0 5px; padding: 3px 5px;
text-align: center; text-align: center;
float: left; float: left;
margin-right: 15px; margin-right: 15px;
text-decoration: none; text-decoration: none;
} }
#try_these { #try_these {
clear: both; clear: both;
} }

View file

@ -1,84 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Franz - client side color palettes from logos</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/example.css">
<script type="text/javascript" src="http://images.webs.com/static/global/js/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/franz.js"></script>
<script type="text/javascript">
var img_input;
$(document).ready(function() {
franz.init("lol");
img_input = document.getElementById("img_input");
$("#franz_form").submit(function() {
franz.loadImg(img_input.value);
$("#hsv").removeClass("hideme");
return false;
});
$("#try_these a").click(function(event){
img_input.value = this.innerHTML;
return false;
});
$("#sort_hue").click(function(event){
franz.displayHue();
return false;
});
$("#sort_sat").click(function(event){
franz.displaySat();
return false;
});
$("#sort_val").click(function(event){
franz.displayVal();
return false;
});
});
</script>
</head>
<body>
<h1>Franz - client side color swatches</h1>
<div id="container_top">
<div id="lol_container">
<canvas id="lol" width="100" height="100"></canvas>
<canvas id="lol_hidden" width="19" height="19"></canvas>
</div>
<div id="interface">
<form method="post" action="#" id="franz_form">
<input type="text" id="img_input" value="lol.png">
<input type="submit" id="img_submit" value="Go for it!">
</form>
<p id="hsv" class="hideme"><a href="#" id="sort_hue">Sort Hue</a> <a href="#" id="sort_sat">Sort Saturation</a> <a href="#" id="sort_val">Sort Value</a> </p>
<p id="try_these"><strong>Try out:</strong> <a href="#">lol.png</a>, <a href="#">testjubs.jpg</a>, <a href="#">stars.jpg</a>, <a href="#">1600.jpg</a>, <a href="#">fallout.jpg</a></p>
</div>
<!-- might log colors later on
<ul id="logHSV">
<li><p id="logHue">Hue: </p></li>
<li><p id="logSat">Sat: </p></li>
<li><p id="logVal">Val: </p></li>
</ul> -->
</div>
<div id="container_bottom">
<div id="log_colors">
</div>
</div>
<p id="footer">
Experiment in color theme generator <br> brought to you by <a href="http://twitter.com/ryanmcgrath" title="Ryan McGrath">Ryan McGrath</a> & <a href="http://twitter.com/enotionz" title="Dominick Pham">Dominick Pham</a>,
with some help from others.
</p>
</body>
</html>

127
index.php Normal file
View file

@ -0,0 +1,127 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Franz - client side color palettes from logos</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/example.css">
<script type="text/javascript" src="http://images.webs.com/static/global/js/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/franz.js"></script>
<script type="text/javascript">
var img_input;
/* Oh god a global function wrrrryyyy */
function lol() {
franz.loadImg(img_input.value);
$("#options").fadeIn("fast");
return false;
}
$(document).ready(function() {
franz.init("lol");
img_input = document.getElementById("img_input");
$("#franz_form").submit(lol);
$("#try_these a").click(function() {
img_input.value = this.innerHTML;
return false;
});
<?php /* This hack sucks, but it's worth it for right now. -- Ryan */
if($_REQUEST["image"])
echo 'img_input.value = "awesome/' . $_REQUEST["image"] . '"; lol();';
?>
$("#sort_hue").click(function() {
franz.displayHue();
return false;
});
$("#sort_sat").click(function() {
franz.displaySat();
return false;
});
$("#sort_val").click(function() {
franz.displayVal();
return false;
});
$("#upload_button").click(function() {
var f_form = $("#franz_form"),
uploader = $("#uploader");
if(f_form[0].style.display == "none") {
uploader.hide();
f_form.fadeIn("slow");
$(this).html("Upload an image");
} else {
f_form.hide();
uploader.fadeIn("slow");
$(this).html("Use an existing image?");
}
return false;
});
});
</script>
</head>
<body>
<h1>Franz - client side color swatches</h1>
<div id="container_top">
<a href="#" title="Upload an image" id="upload_button">Upload an image</a>
<div id="lol_container">
<canvas id="lol" width="100" height="100"></canvas>
<canvas id="lol_hidden" width="19" height="19"></canvas>
</div>
<div id="interface">
<form id="uploader" name="uploader" method="post" action="upload.php" enctype="multipart/form-data">
<input id="file" type="file" name="dragonfruit">
<input type="submit" class="img_submit" value="Upload and be awesome">
</form>
<form method="post" action="#" id="franz_form">
<input type="text" id="img_input" value="lol.png">
<input type="submit" class="img_submit" value="Go for it!">
</form>
<p id="try_these"><strong>Try out:</strong>
<a href="#" title="lol.png">lol.png</a>,
<a href="#" title="testjubs.jpg">testjubs.jpg</a>,
<a href="#" title="stars.jpg">stars.jpg</a>,
<a href="#" title="1600.jpg">1600.jpg</a>,
<a href="#" title="fallout.jpg">fallout.jpg</a>
</p>
</div>
<!-- might log colors later on
<ul id="logHSV">
<li><p id="logHue">Hue: </p></li>
<li><p id="logSat">Sat: </p></li>
<li><p id="logVal">Val: </p></li>
</ul> -->
</div>
<div id="options">
<p id="hsv">
<a href="#" id="sort_hue" title="Sort by Hue">Sort by Hue</a>
<a href="#" id="sort_sat" title="Sort by Saturation">Sort by Saturation</a>
<a href="#" id="sort_val" title="Sort by Value">Sort by Value</a>
</p>
</div>
<div id="container_bottom">
<div id="log_colors">
</div>
</div>
<p id="footer">
This experiment was brought to you in Technicolor (get it?) by <a href="http://twitter.com/ryanmcgrath" title="Ryan McGrath">Ryan McGrath</a> & <a href="http://twitter.com/enotionz" title="Dominick Pham">Dominick Pham</a>,
two of the most awesome people you'll ever hear about.
</p>
</body>
</html>

48
upload.php Normal file
View file

@ -0,0 +1,48 @@
<?php
// Current working directory, relative to root...
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// Directory getting the uploaded file...
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'awesome/';
// Referring upload form. Could probably do this based on the request, but I'm lazy and can't recall how. STFU. >_>
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.html';
// Self explanatory, I would think.
$fieldname = 'dragonfruit';
// Possible upload errors, have some fun here.
$errors = array(1 => 'WTF were you thinking? php.ini max file size was exceeded. Get with the program.',
2 => 'You have *got* to be kidding me - you exceeded the maximum html form file size!',
3 => 'Come on now, that file upload was only partial. (Try again)',
4 => 'Uhh... hello? No file was attached.');
// Check with PHP's built-in uploading errors
($_FILES[$fieldname]['error'] == 0) or error($errors[$_FILES[$fieldname]['error']]);
// Make sure this was really an HTTP upload
@is_uploaded_file($_FILES[$fieldname]['tmp_name']) or error('Not an HTTP upload... (Go back and try again?)');
// Validation hack - just run it through getimagesize() ;)
@getimagesize($_FILES[$fieldname]['tmp_name']) or error('Only image uploads are allowed. (Go back and try again)');
// We need a unique filename. Judge it off the date and such, should prevent 99% of the same-name errors.
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])) {
$now++;
}
// Move to the final location and actually rename.
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename) or error('We have received insufficient permissions. Locked on and ready to fire! (Go back and try again)');
// Redirect to a success page. If we posted this through JS/Iframe or Flash, you'd wanna just return the string filename.
header('Location: index.php?image=' . $now . '-' . $_FILES[$fieldname]['name']);
// Generic error handler. Fuck PHP.
function error($error) {
echo $error;
exit;
}
?>