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"; $this->expiryTime = gmdate('D, d M Y H:i:s', mktime(0, 0, 0, date("m"), date("d")+7, date("Y"))).' GMT'; if($this->style == "admin"){ $this->expiryTime = gmdate('D, d M Y H:i:s', filemtime($this->cache_file)).' GMT'; $this->fontsettings = array(); $this->fontsettings['font-name'] = $this->text; $this->text = $this->displaytext; if($this->displaytext == "charactermap"){ $i = 33; $txt = ""; while($i < 127){ $txt .= "&#$i; "; $i++; } $i = 188; while($i < 255){ $txt .= "&#$i; "; $i++; } $this->text = html_entity_decode(urldecode($txt), ENT_QUOTES); $this->fontsettings["limit-width"] = true; $this->fontsettings["max-width"] = 50; } $this->fontsettings['color'] = "333333"; $this->fontsettings['font-size'] = 18; $this->fontsettings['shadow'] = false; $this->fontsettings['background-color'] = "FFFFFF"; } 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'] = 16; $this->fontsettings['shadow'] = false; $this->fontsettings['background-color'] = "FFFFFF"; }else if(file_exists($stylesheet)){ $styles = parse_ini_file($stylesheet, true); if(isset($styles[$this->style])){ $this->fontsettings = $styles[$this->style]; !isset($this->fontsettings['shadow-distance']) ? $this->fontsettings['shadow-distance'] = 6 : 0; } else { wp_redirect(get_option('siteurl')); } } if(is_array($this->fontsettings)){ $this->fonttype = !file_exists(ANYFONT_FONTDIR."/".$this->fontsettings['font-name'].".ttf") ? ".otf" : ".ttf"; $hash = md5(basename($this->fontsettings['font-name']).$this->fontsettings['color'].$this->fontsettings['soften-shadow'].$this->fontsettings["shadow"].$this->fontsettings['background-color'].$this->fontsettings['font-size'].$this->fontsettings['shadow-color'].$this->fontsettings['shadow-distance'].$this->fontsettings['limit-width'].$this->fontsettings['max-width'].$this->text); $this->etag = $hash; $this->cache_file = ANYFONT_CACHE."/$hash.png"; $this->tmp_file = ANYFONT_FONTDIR."/{$hash}_bg.png"; if(file_exists($this->cache_file)){ if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == gmdate('D, d M Y H:i:s', filemtime($this->file)).' GMT'){ header("HTTP/1.0 304 Not Modified"); } else{ $this->fetchImage(); } } else { $this->text2Image(); } }else{ wp_redirect(get_option('siteurl')); } } function text2Image(){ $style = $this->style; $this->font = ANYFONT_FONTDIR."/".$this->fontsettings['font-name'].$this->fonttype; $this->size = $this->fontsettings['font-size']; // RW : Added this multiline block $this->fontsettings["limit-width"] ? $this->text = wordwrap($this->text, (int)$this->fontsettings["max-width"], "\n", true) : 0; $this->box = imagettfbbox(($this->size*1.05), 0, $this->font, $this->text); $min_x = min(array($this->box[0], $this->box[2], $this->box[4], $this->box[6])); $max_x = max(array($this->box[0], $this->box[2], $this->box[4], $this->box[6])); $min_y = min(array($this->box[1], $this->box[3], $this->box[5], $this->box[7])); $max_y = max(array($this->box[1], $this->box[3], $this->box[5], $this->box[7])); $this->left = abs($min_x)+5; $this->top = abs($min_y); $this->width = ($max_x - $min_x)+15; $this->height = ($max_y + abs($min_y))+15; if($this->fontsettings['shadow']){ $this->width += $this->fontsettings['shadow-distance']; $this->height += $this->fontsettings['shadow-distance']; } $this->bg = @imagecreatetruecolor($this->width, $this->height); $background = $this->hex_to_rgb($this->fontsettings['background-color']); $this->bg_color = @imagecolorallocate($this->bg, $background[0], $background[1], $background[2]); imagefill($this->bg, 0, 0, $this->bg_color); @imagepng($this->bg, $this->tmp_file); $this->img = @imagecreatefrompng($this->tmp_file); $this->bg_color = imagecolorat($this->img, 1, 1); $color = $this->hex_to_rgb($this->fontsettings['color']); $this->font_color = @imagecolorallocate($this->img, $color[0], $color[1], $color[2]); $this->fontsettings["shadow"] ? $this->shadowImage() : 0; imagettftext($this->img, $this->size, 0, $this->left, $this->top, $this->font_color, $this->font, $this->text); imagecolortransparent($this->img, $this->bg_color); @imagepng($this->img, $this->cache_file); imagedestroy($this->img); imagedestroy($this->bg); $this->fetchImage(); unlink($this->tmp_file); } function shadowImage(){ $shadow = @imagecreatefrompng($this->tmp_file); $shadow_rgb = $this->hex_to_rgb($this->fontsettings['shadow-color']); $shadow_color = @imagecolorallocate($shadow, $shadow_rgb[0], $shadow_rgb[1], $shadow_rgb[2]); imagettftext($shadow, $this->size, 0, $this->left+$this->fontsettings['shadow-distance'], $this->top+$this->fontsettings['shadow-distance'], $shadow_color, $this->font, $this->text); $this->fontsettings['soften-shadow'] ? $this->blur($shadow) : 0; imagecopymerge($this->img, $shadow, 0, 0, 0, 0, $this->width, $this->height, 50); imagedestroy($shadow); } function blur($image){ $imagex = imagesx($image); $imagey = imagesy($image); $dist = 4; for($x = 0; $x < $imagex; ++$x){ for($y = 0; $y < $imagey; ++$y){ $newr = 0; $newg = 0; $newb = 0; $colours = array(); $thiscol = imagecolorat($image, $x, $y); if($thiscol != $this->bg_color){ for($k = $x - $dist; $k <= $x + $dist; ++$k){ for($l = $y - $dist; $l <= $y + $dist; ++$l){ if($k < 0){ $colours[] = $thiscol; continue; } if($k >= $imagex){ $colours[] = $thiscol; continue; } if($l < 0){ $colours[] = $thiscol; continue; } if($l >= $imagey){ $colours[] = $thiscol; continue; } $colours[] = imagecolorat($image, $k, $l); } } foreach($colours as $colour) { $newr += ($colour >> 16) & 0xFF; $newg += ($colour >> 8) & 0xFF; $newb += $colour & 0xFF; } $numelements = count($colours); $newr /= $numelements; $newg /= $numelements; $newb /= $numelements; $newcol = imagecolorallocate($image, $newr, $newg, $newb); imagesetpixel($image, $x, $y, $newcol); } } } } function fetchImage(){ $image = !$this->gzip ? file_get_contents($this->cache_file) : gzencode(file_get_contents($this->cache_file)); header('X-Generated-By: AnyFont for WordPress'); $this->gzip ? header('Content-encoding: gzip') : 0; header('Content-type: image/png'); header('Content-length: '.strlen($image)); header('Expires: '.$this->expiryTime); header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($this->cache_file)).' GMT'); header('Etag: '.$this->etag); print($image); } /** Description: Strips slashes and other "bad" characters from a text string for image creation * @param string * @return string of plain text */ function clean_text(){ $this->text = stripslashes($this->text); $matches = null; preg_match_all('/%u([0-9A-F]{4})/i',$this->text,$matches); if(!empty($matches)) for($i=0;$itext = str_replace($matches[0][$i],'&#'.hexdec($matches[1][$i]).';',$this->text); } /** Description: Method to convert colours from the hex format to RGB * @param var hex colour definition * @return var RBG Colour Definition */ function hex_to_rgb($hex){ substr($hex,0,1) == '#' ? $hex = substr($hex,1) : 0; if(strlen($hex) == 3){ $hex = substr($hex,0,1) . substr($hex,0,1). substr($hex,1,1) . substr($hex,1,1). substr($hex,2,1) . substr($hex,2,1); } strlen($hex) != 6 ? $error = 'Error: Invalid color "'.$hex.'"' : 0 ; $rgb[] = hexdec(substr($hex,0,2)); $rgb[] = hexdec(substr($hex,2,2)); $rgb[] = hexdec(substr($hex,4,2)); return $rgb; } }