Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
Images
filetypeMatchesExtension($file)
imagelinerectangle()
issa clock
rotate_wide_line($x, $y, $width, $length, $degrees)
4
found
auth
Name:
Category: Images
Body:
<?php // uses some updated image classes which might not be in this funcs thing.. made at work that one late evening require 'class/image.class.php'; require 'class/image_plus.class.php'; // dimensions and colors $width = 401; $center = floor($width/2); // hours/minutes/seconds stuff $hour_hand = floor(0.5 * $center); $hour_hand_width = 8; $hour_color = 0x2EA399; $minute_hand = floor(0.7 * $center); $minute_hand_width = 4; $minute_color = 0xA0F2E3; $second_hand = floor(1 * $center); $second_color = 'white'; $second_hand_width = 2; list($h, $m, $s) = [true, true, false]; // which to show // the actual time list($hours, $minutes, $seconds) = explode(':', date('H:i:s')); $hours += $minutes/60; $minutes += $seconds/60; if ($hours > 12) $hours -= 12; // start image $I = new Image_Plus($width); $I->bgcolor('red'); // this becomes transparent lateron // hours, minutes, seconds if ($h) $I->poly(rotate_wide_line( $center, $center, $hour_hand_width, $hour_hand, ($hours/12)*360 ), $hour_color, 1); if ($m) $I->poly(rotate_wide_line( $center, $center, $minute_hand_width, $minute_hand, ($minutes/60)*360 ), $minute_color, 1); if ($s) $I->poly(rotate_wide_line( $center, $center, $second_hand_width, $second_hand, ($seconds/60)*360 ), $second_color, 1); // hub & circumference $I->circle($center, $center, 25, 25, 0x3ACDBF, 1); $I->circle($center, $center, $width, $width, 0x3ACDBF, 0); // make it transparent, doing this last prevents some weird anti-aliasing artifacts $I->imagecolortransparent($I->imagecolorallocatealpha(255, 0, 0, 127)); $I->draw(); // rotate_wide_line($x, $y, $width, $length, $degrees) function rotate_wide_line($x, $y, $width, $length, $degrees) { $hw = $width / 2; $degrees = abs($degrees % 360); // normalize $m = ($degrees/360)*2*M_PI; // m for magic $lx = $x + sin($m) * $length; // these are what the end points of the line would be $ly = $y - cos($m) * $length; // we'll add offsets. $m2 = (($degrees-90)/360)*2*M_PI; // m for width magic $coords[0] = $x - sin($m2) * $hw; // these are the x/y coords of the "first" corner of the resulting polygon $coords[1] = $y + cos($m2) * $hw; $ox = $x - $coords[0]; // grab some offsets $oy = $y - $coords[1]; $coords[2] = $x + $ox; // and apply to line coords for the rest of the coords $coords[3] = $y + $oy; $coords[4] = $lx + $ox; $coords[5] = $ly + $oy; $coords[6] = $lx - $ox; $coords[7] = $ly - $oy; return $coords; }
Footer