text = $text : 0; isset($style) ? $this->style = $style : 0; isset($displaytext) ? $this->displaytext = $displaytext : 0; isset($gzip) ? $this->gzip = $gzip : 0; $stylesheet = ANYFONT_FONTDIR."/styles.ini"; if($this->style == "admin"){ $this->fontsettings = array(); $this->fontsettings['font-name'] = $this->text; $this->text = $this->displaytext; if($this->displaytext == "charactermap"){ $i = 33; $txt = ""; while($i <= 126){ $txt .= "&#$i; "; $i++; } $i = 188; while($i <= 255){ $txt .= "&#$i; "; $i++; } $this->text = html_entity_decode(urldecode($txt), ENT_QUOTES); } $this->fontsettings['color'] = "333333"; $this->fontsettings['font-size'] = 24; $this->fontsettings['shadow'] = false; $this->fontsettings['shadow-color'] = "FFFFFF"; $this->fontsettings["limit-width"] = true; $this->fontsettings["max-width"] = (32*3); $this->fontsettings['is_admin'] = true; } else if($this->style == "admin-small"){ $this->fontsettings = array(); $this->fontsettings['font-name'] = $this->text; $this->text = $this->displaytext; $this->fontsettings['color'] = "333333"; $this->fontsettings['font-size'] = 20; $this->fontsettings['shadow'] = false; $this->fontsettings['shadow-color'] = "FFFFFF"; $this->fontsettings['shadow-spread'] = 0; $this->fontsettings['is_admin'] = true; }else if(file_exists($stylesheet)){ $styles = parse_ini_file($stylesheet, true); if(isset($styles[$this->style])){ $this->fontsettings = $styles[$this->style]; } else { wp_redirect(get_option('siteurl')); exit(0); } } if(is_array($this->fontsettings)){ $this->linecount = 1; if ($this->fontsettings["limit-width"]){ $this->text = wordwrap($this->text, (int)$this->fontsettings["max-width"], "\n", true); } !isset($this->fontsettings['shadow-distance']) ? $this->fontsettings['shadow-distance'] = 1 : 0; !isset($this->fontsettings['shadow-spread']) ? $this->fontsettings['shadow-spread'] = 1 : 0; !isset($this->fontsettings['image-padding']) ? $this->fontsettings['image-padding'] = 0 : 0; !isset($this->fontsettings['image-padding-radius']) ? $this->fontsettings['image-padding-radius'] = 0 : 0; $this->fonttype = !file_exists(ANYFONT_FONTDIR."/".$this->fontsettings['font-name'].".ttf") ? ".otf" : ".ttf"; $pre_hash = ""; foreach($this->fontsettings as $value){ $pre_hash.=$value; } $hash = md5($pre_hash.$this->text."imagick"); $this->etag = $hash; if(!isset($this->fontsettings['is_admin'])){ $this->cache_file = ANYFONT_CACHE."/$hash-site.png"; } else { $this->cache_file = ANYFONT_CACHE."/$hash-admin.png"; } if(file_exists($this->cache_file)){ if(isset($_SERVER["HTTP_IF_NONE_MATCH"]) || isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ if($_SERVER["HTTP_IF_NONE_MATCH"] == $this->etag || $_SERVER['HTTP_IF_MODIFIED_SINCE'] == gmdate('D, d M Y H:i:s', filemtime($this->cache_file)).' GMT'){ header("HTTP/1.0 304 Not Modified"); exit(304); } else { self::text2Image(); } } else { self::printImage(); } } else { self::text2Image(); } } } /** Description * Creates a png image from a text string using truetype fonts and writes the file to cache */ private function text2Image(){ $image = new Imagick(); $draw = new ImagickDraw(); $draw->setFillColor(new ImagickPixel("#".$this->fontsettings['color'])); $draw->setFont(ANYFONT_FONTDIR."/".$this->fontsettings['font-name'].$this->fonttype); $draw->setFontSize($this->fontsettings['font-size']); // $lines = substr_count($this->text, "\n"); // $lines+=1; $fm = $image->queryFontMetrics($draw, $this->text, true); $min_y = min(array($fm["boundingBox"]["y2"],$fm["boundingBox"]["y1"])); $max_y = max(array($fm["boundingBox"]["y2"],$fm["boundingBox"]["y1"])); $padding = !$this->fontsettings['image-padding'] ? 0 : $this->fontsettings['image-padding-radius']; $shadowspread = !$this->fontsettings['shadow'] ? 0 : $this->fontsettings['shadow-spread']; $width = $fm["textWidth"]+5+($padding*2); $height = $max_y+abs($min_y)+($padding*2); $this->fontsettings["limit-width"] ? $height = $fm["textHeight"] : 0; if($this->fontsettings['shadow']){ $height += ((int)$this->fontsettings['shadow-distance']+((int)$this->fontsettings['shadow-spread']*2.8)); $width += ((int)$this->fontsettings['shadow-distance']+((int)$this->fontsettings['shadow-spread']*2.8)); } $fcm = $image->queryFontMetrics($draw, substr($this->text, 0, 1)); $min_x = min(array($fcm["boundingBox"]["x2"],$fcm["boundingBox"]["x1"])); $x = abs($min_x)+$shadowspread+$padding; $y = $max_y+$shadowspread+$padding; $image->newImage($width, $height, "transparent", "png"); if($this->fontsettings['shadow']){ $shadow = new ImagickDraw(); $shadow->setFillColor(new ImagickPixel("#".$this->fontsettings['shadow-color'])); $shadow->setFont(ANYFONT_FONTDIR."/".$this->fontsettings['font-name'].$this->fonttype); $shadow->setFontSize($this->fontsettings['font-size']); $image->annotateImage($shadow, $x+$this->fontsettings['shadow-distance'], $y+$this->fontsettings['shadow-distance'], 0, $this->text); $this->fontsettings['shadow-spread'] > 0 ? $image->blurImage(0, (int)$this->fontsettings['shadow-spread']) : 0; } $image->annotateImage($draw, $x, $y, 0, $this->text); $image->writeImage($this->cache_file); self::printImage($image); } /** Description * Fetches the image from cache and delivers it to the browser along with the required headers. * @prints PNG image */ private function printImage($img=false){ !$img ? $img = file_get_contents($this->cache_file) : 0; header('Content-type: image/png'); $this->gzip ? $img = gzencode($img) : 0; $this->gzip ? header('Content-encoding: gzip') : 0; header('X-Generated-By: AnyFont v'.ANYFONT_VERSION.' for WordPress'); header('Content-length: '.strlen($img)); header('Last-modified: '.gmdate('D, d M Y H:i:s', filemtime($this->cache_file)).' GMT'); header('Etag: "'.$this->etag.'"'); print($img); } } ?>