Sure, the hover thing is pretty easy to if you change the original code slightly.
PHP Code:
<?php
$isImageRequest = array_key_exists('colour', $_GET);
if($isImageRequest)
{
$template = imagecreatefrompng('t-shirt.png');
imagetruecolortopalette($template, true, 255);
list($r, $g, $b) = explode(',', $_GET['colour']);
imagecolorset(
$template,
imagecolorat($template, 100, 100),
$r,
$g,
$b
);
header('Content-Type: image/png');
imagepng($template);
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssbase/base-min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts-min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<title>
Sitepoint Demo
</title>
</head>
<body>
<h1>
Pink T-Shirt!
</h1>
<img id="preview" src="index.php?colour=255,0,199" alt="t-shirt image" />
<div id="controls">
<p>See it in ... </p>
<a class="c" rel="255,0,0" href="#">
Red
</a>
<a class="c" rel="0,255,0" href="#">
Green
</a>
<a class="c" rel="0,0,255" href="#">
Blue
</a>
<a class="c" rel="255,255,255" href="#">
White
</a>
<a class="c" rel="0,0,0" href="#">
Black
</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('a.c').hover(
function(){
$('#preview').attr('src', 'index.php?colour=' + $(this).attr('rel'));
},
function(){
$('#preview').attr('src', 'index.php?colour=255,0,199');
}
);
});
</script>
</body>
</html>
I've updated the demo to show this revision.
Bookmarks