WebsiteBaker 2.13.9 is now available!
R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WBhttps://forum.websitebaker.org/index.php/topic,32355.0.html
Text2png
$cache_dir = WB_PATH.'/temp/';$fontfile = WB_PATH.'/media/fonts/'.$ttffile;$fontangle = 0;if (!isset($fontsize)) $fontsize = "12";if (!isset($fontcolor)) $fontcolor = "000000";$cache_file = 'text2png_'.md5($text.$fontfile.$fontsize.$fontcolor).'.png';if (!file_exists($cache_dir.$cache_file)) {$box = @imagettfbbox($fontsize, $fontangle, $fontfile, $text); $textwidth = abs($box[4] - $box[0]); $textheight = abs($box[5] - $box[1]); $imagewidth = $textwidth+10; $imageheight = $textheight+10; $xcord = ($imagewidth/2)-($textwidth/2)-2; $ycord = ($textheight/2)-2; $img = imagecreatetruecolor($imagewidth, $imageheight); imagealphablending($img, false); imagesavealpha($img, true); imageantialias($img, true); $opaque = imagecolorallocatealpha($img, 0, 0, 0, 0); $transparent = imagecolorallocatealpha($img, 0, 0, 0, 127); imagefilledrectangle($img, 0,0, $imagewidth, $imageheight, $transparent); if( eregi( "([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})", $fontcolor, $textrgb ) ) {$textred = hexdec( $textrgb[1] ); $textgreen = hexdec( $textrgb[2] ); $textblue = hexdec( $textrgb[3] );} $opaque = imagecolorallocate($img, $textred, $textgreen, $textblue); imagettftext($img, $fontsize, $fontangle, $xcord, $ycord, $opaque , $fontfile, $text); // invert alpha channel for($i=0;$i<$xsize;$i++) {for($j=0;$j<$ysize;$j++) {$color = imagecolorat($img, $i, $j); $color = ($color & 0x00FFFFFF) | ((127-($color>>24))<<24); imagesetpixel($img, $i, $j, $color); } } imagepng($img, $cache_dir.$cache_file); imagedestroy($img); }return '<img src="'.WB_URL.'/temp/'.$cache_file.'" style="border:0px;margin:0px;padding:0px;vertical-align:middle;" alt="'.$text.'"/>';
Use: [[Text2png?text=(text, Mandatory)&ttffile=(fontfile.ttf, Mandatory)&fontcolor=(fontcolor, Optional)&fontsize=(fontsize, Optional)]]text = Text to convert into truecolor png with transparent background.ttffile = True Type Font file (.ttf or .otf), must be in the folder media/fonts/ but you can change this in the code.fontcolor = Color in 6 digit HEX format, "000000"(black) by default.fontsize = Size of the font in points (if gd2 is used, otherwise in pixels), 12 by default.This droplet has a rudimentary but efficient caching system but it never delete any file, if you want you can delete all the png files starting with the name "text2png_" in your temp folder, droplet will recreate the needed files.
$cache_dir = WB_PATH.'/temp/';$fileduration = "1 hour";$fontfile = WB_PATH.'/media/fonts/'.$ttffile;$fontangle = 0;if (!isset($fontsize)) $fontsize = "12";if (!isset($fontcolor)) $fontcolor = "000000";$cache_file = 'text2png_'.md5($text.$fontfile.$fontsize.$fontcolor).'.png';$cdir = opendir($cache_dir) or die ('Could not open '.$cache_dir);while ($file = readdir($cdir)) { if ((preg_match('/text2png_/',$file)) && (filemtime($cache_dir.$file)) < (strtotime('-'.$fileduration))) { unlink($cache_dir.$file); }}if (!file_exists($cache_dir.$cache_file)) {$box = @imagettfbbox($fontsize, $fontangle, $fontfile, $text); $textwidth = abs($box[4] - $box[0]); $textheight = abs($box[5] - $box[1]); $imagewidth = $textwidth+10; $imageheight = $textheight+10; $xcord = ($imagewidth/2)-($textwidth/2)-2; $ycord = ($imageheight /1.33); $img = imagecreatetruecolor($imagewidth, $imageheight); imagealphablending($img, false); imagesavealpha($img, true); imageantialias($img, true); $opaque = imagecolorallocatealpha($img, 0, 0, 0, 0); $transparent = imagecolorallocatealpha($img, 0, 0, 0, 127); imagefilledrectangle($img, 0,0, $imagewidth, $imageheight, $transparent); if( eregi( "([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})", $fontcolor, $textrgb ) ) {$textred = hexdec( $textrgb[1] ); $textgreen = hexdec( $textrgb[2] ); $textblue = hexdec( $textrgb[3] );} $opaque = imagecolorallocate($img, $textred, $textgreen, $textblue); imagettftext($img, $fontsize, $fontangle, $xcord, $ycord, $opaque , $fontfile, $text); // invert alpha channel for($i=0;$i<$xsize;$i++) {for($j=0;$j<$ysize;$j++) {$color = imagecolorat($img, $i, $j); $color = ($color & 0x00FFFFFF) | ((127-($color>>24))<<24); imagesetpixel($img, $i, $j, $color); } } imagepng($img, $cache_dir.$cache_file); imagedestroy($img); } return '<img src="'.WB_URL.'/temp/'.$cache_file.'" style="border:0px;margin:0px;padding:0px;vertical-align:middle;" alt="'.$text.'"/>';