Page 1 of 3
"Please, share the secret..."
Posted: Tue Dec 14, 2004 1:18 am
by Richard K Niner
I know! Please, share the secret...
Well, okay, but only because you asked so nicely...
To summarize, though, I just told my server to redirect any traffic from a .png file to a .php file that can randomize my avatar.
And now the gory details:
For simplicity, ${AV_DIR}/av.png is the address of the randomized avatar, and the source images are in ${AV_DIR}/avatar/.
Code: Select all
From ${AV_DIR}/.htaccess:
AddHandler cgi-script .png
From ${AV_DIR}/avatar/.htaccess:
RemoveHandler .png
From ${AV_DIR}/av.png:
#!/xhbin/php
<?php
//Init
$nTotal = 0;
$fn = explode('/', $_GET['fileName']);
$fn = $fn[count($fn) - 1];
if (strpos($fn,'av.png') == false) {
$fn = "";
}
// Was a filename passed?
if ($fn == "") {
$path = './avatar/';
$dir = opendir($path);
if ($dir !== false) {
while (false !== ($file = readdir($dir))) {
if ((strpos($file,'.png') || strpos($file,'.gif') ||
strpos($file,'.jpg')) && strpos($file,'av.png') === false) {
$img[$nTotal] = $file;
$nTotal++;
}
}
closedir($dir);
}
$now = time();
$nToday = 0;
for ($i = 0; $i < $nTotal; $i++) {
$date[$i] = filemtime($path.$img[$i]);
if ($now - $date[$i] <= 86400) {
$today[$nToday] = $img[$i];
$nToday++;
}
}
$fn = "";
if ($nToday > 0) {
$num = rand(0, $nToday - 1);
$fn = $today[$num];
} elseif ($nTotal > 0) {
$num = rand(0, $nTotal - 1);
$fn = $img[$num];
}
}
if ($fn != "") {
// header("HTTP/1.1 302 Found");
header("Content-Type: image/png");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$fp = fopen($path.$fn, 'r');
while (!feof($fp)) {
echo fread($fp, 8192);
}
fclose($fp);
exit;
}
header("HTTP/1.1 404 Not Found");
header("Content-Type: application/xhtml+xml");
header("Cache-Control: no-cache");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>404 Not Found</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
<meta name="robots" content="noindex,noarchive,nofollow" />
</head>
<body>
<h1>404 Not Found</h1>
<p>
A suitable resource has not been found. Unfortunately, there are no avatars
available in this folder. As a result, You are seeing this error page
instead.
</p>
<div>Possible solutions include:<br />
<ul>
<li><a href="javascript:location.href=location.href;">Reload</a>ing this
page</li>
<li><a href="mailto:my@email.address">Email</a>ing me, and begging me to
fix it</li>
<li>Or, just living with these results</li>
</ul>
What you do, then, is up to you</div>
</body>
</html>
Some notes:
I removed my email address from the above code to prevent potential spamming
The line that says "#!/xhbin/php" is needed only because of my server's configuration, and will probably not work on your server. If you are not using that line, the .htaccess file may require "AddHandler application/x-httpd-php .png" instead. Experiment around until it works.
EDIT: Removed dead link, added source code instead.
EDIT: Fixed for use in phpBB
Posted: Tue Dec 14, 2004 2:29 am
by Supersmoke
It's cool, but you think you can do it with .jpg's?<br>.png files take too long to load. <!--emo&<_<--><img src='
http://definecynical.mancubus.net/forum ... ns/dry.gif' border='0' style='vertical-align:middle' alt='dry.gif' /><!--endemo-->
Posted: Tue Dec 14, 2004 2:40 am
by Richard K Niner
Of course - just replace ".png" with ".jpg", and "image/png" with "image/jpeg". The same trick should work for gifs as well.<br><br>Personally, though, I prefer PNG because I can do things with it that I can't with JPEG - like alpha transparency, 24-bit colour, and lossless compression simultaeneously. (But, then again, PNG files are larger than JPEGs...)
Posted: Tue Dec 14, 2004 5:53 am
by Softpaw
[poke] Alpha transparency in PNGs doesn't show up for 95% of people (aka IE users) <!--emo&:P--><img src='
http://definecynical.mancubus.net/forum ... tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo-->
Posted: Tue Dec 14, 2004 6:27 am
by Burning Sheep Productions
It doesn't?<br>Hrmm...
Posted: Tue Dec 14, 2004 7:38 am
by Ruedii-X
<!--QuoteBegin-FelixSoftpaw+Dec 14 2004, 12:53 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (FelixSoftpaw @ Dec 14 2004, 12:53 AM)</td></tr><tr><td class='quotebody'> [poke] Alpha transparency in PNGs doesn't show up for 95% of people (aka IE users) <!--emo&:P--><img src='
http://definecynical.mancubus.net/forum ... tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo--> <!--QuoteEnd--> </td></tr></table> <!--QuoteEEnd--><br> Those people should get a compliant browser. <!--emo&:P--><img src='
http://definecynical.mancubus.net/forum ... tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo--> <!--emo&:P--><img src='
http://definecynical.mancubus.net/forum ... tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo-->
Posted: Tue Dec 14, 2004 11:53 am
by Kles
Come on. What would you rather have? A fox for a fricken' floating E? Choice is easy; Firefox is just plain better <!--emo&:D--><img src='
http://definecynical.mancubus.net/forum ... iggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /><!--endemo-->
Posted: Tue Dec 14, 2004 2:38 pm
by Gizensha
<!--QuoteBegin-FelixSoftpaw+Dec 14 2004, 05:53 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (FelixSoftpaw @ Dec 14 2004, 05:53 AM)</td></tr><tr><td class='quotebody'> [poke] Alpha transparency in PNGs doesn't show up for 95% of people (aka IE users) <!--emo&:P--><img src='
http://definecynical.mancubus.net/forum ... tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo--> <!--QuoteEnd--> </td></tr></table> <!--QuoteEEnd--><br> I thought they'd fixed that in some cases. For example, I'm fairly sure the avatars on Gaia are done via pngs for alpha transparancy. I do think they have to be configured to work on IE, though.<br><br>...And please, last I checked it was about 85-90% of internet users nowadays.
Posted: Tue Dec 14, 2004 2:51 pm
by Supersmoke
.jpg = instant loading.<br>.png = 5-10 seconds of loading.<br><br>Save bandwidth, convert to .jpg now!<br><span style='font-size:8pt;line-height:100%'>Or I'll eat you.</span>
Posted: Tue Dec 14, 2004 3:59 pm
by Ruedii-X
<!--QuoteBegin-Kles+Dec 14 2004, 06:53 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (Kles @ Dec 14 2004, 06:53 AM)</td></tr><tr><td class='quotebody'> Come on. What would you rather have? A fox for a fricken' floating E? Choice is easy; Firefox is just plain better <!--emo&:D--><img src='
http://definecynical.mancubus.net/forum ... iggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /><!--endemo--> <!--QuoteEnd--> </td></tr></table> <!--QuoteEEnd--><br> Yep, except it's not a fox, it's a firefox:<br><br>I should pull the link but I'm too lazy. Long story short, firefoxes are technically related to Pandas.
Posted: Tue Dec 14, 2004 4:41 pm
by Richard K Niner
<!--QuoteBegin-FelixSoftpaw+Dec 14 2004, 12:53 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (FelixSoftpaw @ Dec 14 2004, 12:53 AM)</td></tr><tr><td class='quotebody'> [poke] Alpha transparency in PNGs doesn't show up for 95% of people (aka IE users) <!--emo&:P--><img src='
http://definecynical.mancubus.net/forum ... tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo--><!--QuoteEnd--></td></tr></table> <!--QuoteEEnd--><br>Well, that can be solved through the use of certain scripts:<br><!--c1--> <table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1--><script language="JavaScript"><br>function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.<br> {<br> for(var i=0; i<document.images.length; i++)<br> {<br> var img = document.images
<br> var imgName = img.src.toUpperCase()<br> if (imgName.substring(imgName.length-3, imgName.length) == "PNG")<br> {<br> var imgID = (img.id) ? "id='" + img.id + "' " : ""<br> var imgClass = (img.className) ? "class='" + img.className + "' " : ""<br> var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "<br> var imgStyle = "display:inline-block;" + img.style.cssText <br> if (img.align == "left") imgStyle = "float:left;" + imgStyle<br> if (img.align == "right") imgStyle = "float:right;" + imgStyle<br> if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle <br> var strNewHTML = "<span " + imgID + imgClass + imgTitle<br> + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"<br> + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"<br> + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" <br> img.outerHTML = strNewHTML<br> i = i-1<br> }<br> }<br> }<br>window.attachEvent("onload", correctPNG);<br></script><!--c2--></td></tr></table> <!--ec2--><br>Personally, though, I think Microsoft should fix that to make alpha transparency the default behaviour - that is a heckuvalotta code to write. (Relying on it to make the page viewable in all browsers sloooooooows IE to a crawl - sometimes even crashes it!) <!--emo&<_<--><img src='http://definecynical.mancubus.net/forum ... ns/dry.gif' border='0' style='vertical-align:middle' alt='dry.gif' /><!--endemo--><br><br><!--QuoteBegin-Ruedii-X+Dec 14 2004, 10:59 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (Ruedii-X @ Dec 14 2004, 10:59 AM)</td></tr><tr><td class='quotebody'> <br>I should pull the link but I'm too lazy. Long story short, firefoxes are technically related to Pandas.<!--QuoteEnd--></td></tr></table> <!--QuoteEEnd--><br>Actually, red pandas have nothing in common with pandas except their name
Posted: Tue Dec 14, 2004 5:48 pm
by Ruedii-X
<!--QuoteBegin-Richard K Niner+Dec 14 2004, 11:41 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (Richard K Niner @ Dec 14 2004, 11:41 AM)</td></tr><tr><td class='quotebody'> <!--QuoteBegin-Ruedii-X+Dec 14 2004, 10:59 AM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (Ruedii-X @ Dec 14 2004, 10:59 AM)</td></tr><tr><td class='quotebody'> <br>I should pull the link but I'm too lazy. Long story short, firefoxes are technically related to Pandas.<!--QuoteEnd--></td></tr></table> <!--QuoteEEnd--><br>Actually, red pandas have nothing in common with pandas except their name <!--QuoteEnd--></td></tr></table> <!--QuoteEEnd--><br>They're a distant relative to pandas, VERY distant. Nothing like the Chinese Panda. They look like a cross between a small red fox and a small racoon.<br><br>--Ammendum<br>You forgot the code to verify that you were using IE before launching the routine. *Nitpicking*<br><br>You might also be able to fix them with streight out stylesheets. I'm not too familiar. I don't write IE compliant code as a matter of protest. I avoid "fatal errors" but don't write code to look nice on IE. A minor malfunction, such as black background on an Alpha-transparency PNG can be tollerated, so long as your code isn't dependent on it.
Posted: Tue Dec 14, 2004 6:12 pm
by Steve the Pocket
Actually IE <i>does</i> load alpha transparency, but it treats it in the most redarded way imaginable: <i>it puts a light-gray box behind it!</i> For no logical reason! (Sigh...) <!--emo&<_<--><img src='
http://definecynical.mancubus.net/forum ... ns/dry.gif' border='0' style='vertical-align:middle' alt='dry.gif' /><!--endemo-->
Posted: Tue Dec 14, 2004 6:20 pm
by Ruedii-X
<!--QuoteBegin-Octan+Dec 14 2004, 01:12 PM--> <table border='0' align='center' width='95%' ><tr><td class='quotetop'><b>Quote:</b> (Octan @ Dec 14 2004, 01:12 PM)</td></tr><tr><td class='quotebody'> Actually IE <i>does</i> load alpha transparency, but it treats it in the most redarded way imaginable: <i>it puts a light-gray box behind it!</i> For no logical reason! (Sigh...) <!--emo&<_<--><img src='
http://definecynical.mancubus.net/forum ... ns/dry.gif' border='0' style='vertical-align:middle' alt='dry.gif' /><!--endemo--> <!--QuoteEnd--></td></tr></table> <!--QuoteEEnd--><br>That's the default behavior of alpha transparency if not properly loaded. You place a background color, instead of using the graphic engine properly.<br><br>--Ammendum<br>Mozilla 0.5-0.9 had a similar bug in a specific stylesheet "quirk" that was fequently produced by many popular stylesheet generaters. This was classified as a release class critical bug (a step below security class) and marked as having to be fixed by 1.0. Technically Firefox is Mozilla 2.0, dispite the fact that no Main-tree branch has been made with the 2.0 engine (although backports of large segments such as plugin and extension code have been done.)
Posted: Tue Dec 14, 2004 6:27 pm
by NHJ BV
How did this thread evolve into a discussion of IE's lack of .png alpha transparancy and pandas? <!--emo&:blink:--><img src='
http://definecynical.mancubus.net/forum ... /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' /><!--endemo-->