Users browsing this thread: 2 Guest(s)
JavaScript -> Auto-updating Image
#16
Code:
$url = "http://thedilbertstore.com/images/periodic_content/dilbert/dt".date("ymd")."dhct.jpg";

One liner for the URL, lol. Compare it to the GIF version:

Code:
$url = "http://www.dilbert.com/dyn/str_strip/"; // base URL
$dirSize = 9; // Number of 0s in the most significant digit for the Dilbert GIF images.
$baseDate = strtotime("2013-11-08"); // UNIX timestamp, reference date for getting future strips.
$curDate = strtotime('now');
$baseIndex = 202256;

// Subtract UNIX timestamps and divide by 86,400 to get the days (decimal), then floor() it to remove the decimal.
$curIndex = $baseIndex + floor(($curDate - $baseDate) / 86400 );
$dirDiff = $dirSize - strlen($baseIndex); // Get the current number of unused significant directory digits.
$paddedIndex = str_repeat("0", $dirDiff) . $curIndex; // Sort-of hacky but it feels like the easiest way to deal with the 0'd directories.

// The two least significant digits of the index don't matter, everything beforehand is used in the URL directory listing.
for($i = 0; $i < $dirSize - 2; $i++)
{
  // Add "$dirsize - (i + 1)" 0s to the current digit directory to pad it out accordingly
  $url .= $paddedIndex[$i] . str_repeat("0", $dirSize - ($i + 1)) . "/";
}

$url .= "{$curIndex}/{$curIndex}.strip.gif";

Will make the image generation/caching code tonight if I can stop faffing about.
Thanked by: puggsoy


Messages In This Thread
JavaScript -> Auto-updating Image - by puggsoy - 11-06-2013, 03:51 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-08-2013, 10:58 AM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-08-2013, 04:28 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-08-2013, 02:38 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-08-2013, 08:48 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-09-2013, 07:18 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-09-2013, 10:32 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-09-2013, 10:56 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-09-2013, 11:16 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-10-2013, 01:38 AM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-10-2013, 10:58 AM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-10-2013, 03:04 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-10-2013, 06:37 PM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-11-2013, 02:03 AM
RE: JavaScript -> Auto-updating Image - by Phaze - 11-11-2013, 07:16 PM

Forum Jump: