/** * generates an image from arbitrary text. * @param string text to place on image * @param string file name * @return void */ function generate($name, $overwrite = false) { $text = self::get_surname($name->sortkeyprefix); $filename = $name->pageid; $options = wkwThemeAdmin::get_datascape_options(); /* get image path */ $uploads_dir = wp_upload_dir(); $namesDir = $uploads_dir["basedir"] . "/wkw-cache/names"; $filename = $namesDir . "/" . $filename . ".png"; if (file_exists($filename)) { if ($overwrite) { @unlink($filename); } else { return; } } /* settings */ $fontPath = get_template_directory() . '/fonts/HandsomePro-Extended.ttf'; $fontSize = $options["fontsize"]; $textcolour = $name->urltitle ? wkwThemeAdmin::hex2RGB($options["names_colour"]) : wkwThemeAdmin::hex2RGB($options["names_colour_unlinked"]); /* get dimensions of image */ $bbox = imagettfbbox($fontSize, 0, $fontPath, $text); $width = $bbox[4] + 24; $height = $fontSize * 2; /* set baseline */ $y = $fontSize * 1.25; /* create image */ $im = self::createImage($width, $height); /* set colour */ $colour = imagecolorallocate($im, $textcolour["red"], $textcolour["green"], $textcolour["blue"]); /* Add the text */ imagettftext($im, $fontSize, 0, 12, $y, $colour, $fontPath, $text); /* save image */ imagepng($im, $filename, 9); /* clean up */ imagedestroy($im); }
<?php /** * culturalcartography.net theme header * @author Peter Edwards <*****@*****.**> * @package WordPress * @subpackage WKW */ $options = wkwThemeAdmin::get_wkw_options(); ?> <!doctype html> <!--[if IEMobile 7]><html class="no-js iem7"><![endif]--> <!--[if (gt IEMobile 7)|!(IEMobile)]><!--><html class="no-js" lang="en"><!--<![endif]--> <!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]--> <!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en"><!--<![endif]--><head> <meta charset="<?php bloginfo('charset'); ?> " /> <title><?php /* * Print the <title> tag based on what is being viewed. */ wp_title('|', true, 'right'); // Add the blog name. bloginfo('name'); // Add a page number if necessary: global $page, $paged; if ($paged >= 2 || $page >= 2) {
$rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2)); $rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2)); $rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2)); } else { return false; } return $returnAsString ? implode($separator, $rgbArray) : $rgbArray; // returns the rgb string or the associative array } /** * Extract a HEX colour and opacity from rgba colour */ function rgba2hexop($rgbaStr) { if (preg_match('/rgba\\(([0-9]+),([0-9]+),([0-9]+),([0-9\\.]+)\\)/', $rgbaStr, $matches)) { $hexStr = ''; for ($i = 1; $i < 4; $i++) { $hex = dechex($matches[$i]); if (strlen($hex) == 1) { $hex = "0" . $hex; } $hexStr .= $hex; } return array('hex' => '#' . $hexStr, 'op' => floatval($matches[4])); } else { return array('hex' => '#000000', 'op' => 0.5); } } } wkwThemeAdmin::register(); }
$pageid = $name->pageid; $title = $name->title; $urltitle = $name->urltitle; $surname = $name->surname; $lastmod = $name->lastmod; break; } } } if (!$pageid) { /* get a random page if none specified */ $rand_index = array_rand($all_names); header("Location: " . get_bloginfo("url") . "/names/" . $all_names[$rand_index]->urltitle); exit; } $datascape_options = wkwThemeAdmin::get_datascape_options(); ?> <!doctype html><!--[if IEMobile 7]><html class="no-js iem7"><![endif]--> <!--[if (gt IEMobile 7)|!(IEMobile)]><!--><html class="no-js" lang="en"><!--<![endif]--><!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]--> <!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en"><!--<![endif]--><head> <meta charset="<?php bloginfo('charset'); ?> " /> <title>Who Knew Whom</title> <meta name="HandheldFriendly" content="True"> <meta name="MobileOptimized" content="320"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- main stylesheet -->