Changeset 1408 in ExiteCMS for branches/PLi-Fusion/includes/font2image.php
- Timestamp:
- 05/15/08 22:25:54 (4 years ago)
- File:
-
- 1 edited
-
branches/PLi-Fusion/includes/font2image.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/PLi-Fusion/includes/font2image.php
r1343 r1408 1 1 <?php 2 2 /* 3 Dynamic Heading Generator 4 Original code by Stewart Rosenberger, http://www.stewartspeak.com/headings/ 5 6 Converted by WanWizard to work in am ExiteCMS environment 7 8 usage: $image_resource = font2image($f2i_array); 9 10 $f2i_array = array(); 11 $f2i_array['image'] = "png"; // Type of image to generate. If not specified, defaults to PNG 12 $f2i_array['font_text'] = "Text to convert"; // Text to convert to an image. Required. 13 $f2i_array['font_file'] = "font2use.ttf"; // FQN of the TTF font file to use. Required. 14 $f2i_array['font_size'] = 10; // Font size. Optional. Valid values are 4 to 96. Default = 10. 15 $f2i_array['font_color'] = "#000000"; // Font color (html style). Default = black. 16 $f2i_array['font_spacing'] = false; // Use the standard font spacing. Default = false. 17 // Disables kerning, outline and shadows!! 18 $f2i_array['font_kerning'] = 0; // Additional space between characters in pixels. Default = 0, Max = 20. 19 $f2i_array['background_color'] = "#FFFFFF"; // Image background color (html style). Default = white. 20 $f2i_array['background_shadow_color'] = "#000000"; // Image shadow background color for a 3D look (html style). Default black. 21 $f2i_array['background_shadow_width'] = 0; // Width of the background shadow of the image. Default = 0, Max = 10. 22 $f2i_array['outline_color'] = ""; // Outline color (html style). If not specified, width is set to 0. 23 $f2i_array['outline_width'] = 0; // Width of the outline of the character in pixels. Default = 0, Max = 10. 24 $f2i_array['shadow_color'] = ""; // Shadow color (html style). If not specified, width is set to 0. 25 $f2i_array['shadow_width'] = 0; // Width of the shadow of the character in pixels. Default = 0, Max = 10. 26 $f2i_array['background_transparent'] = false; // Should the background color be marked transparent? Boolean, default = false; 27 $f2i_array['background_transparent_color'] = ""; // Optional. If defined, this color will be used for transparancy instead of 28 // the specified background color. Required if a background shadow is defined 29 $f2i_array['cache_images'] = false; // Cache the image after generation? Boolean, default = false. 30 $f2i_array['cache_folder'] = ""; // Directory to store the cached images in. 31 // If not defined or not valid, cache_images will be set to false. 32 $f2i_array['cache_prefix'] = false; // If defined, this will be prepended to the filename of the cached file 33 $f2i_array['cache_hash'] = false; // Boolean. If false, the text will be used as filename, otherwise a hash is calculated 34 35 Notes: 36 * if the background has a shadow, background transparency is used to create the 3D effect. The text background 37 itself can therefore not be transparent. 3 Original code by Stewart Rosenberger, http://www.stewartspeak.com/headings/ 4 5 Converted and extended by WanWizard to work in am ExiteCMS environment 6 7 usage: $image_resource = font2image($f2i_array); 8 9 $f2i_array = array(); 10 $f2i_array['image'] = "png"; // Type of image to generate. If not specified, defaults to PNG 11 $f2i_array['font_text'] = "Text to convert"; // Text to convert to an image. Required. 12 $f2i_array['font_file'] = "font2use.ttf"; // FQN of the TTF font file to use. Required. 13 $f2i_array['font_size'] = 10; // Font size. Optional. Valid values are 4 to 96. Default = 10. 14 $f2i_array['font_color'] = "#000000"; // Font color (html style). Default = black. 15 $f2i_array['font_spacing'] = false; // Use the standard font spacing. Default = false. 16 // Disables kerning, outline and shadows!! 17 $f2i_array['font_kerning'] = 0; // Additional space between characters in pixels. Default = 0, Max = 20. 18 $f2i_array['background_color'] = "#FFFFFF"; // Image background color (html style). Default = white. 19 $f2i_array['background_shadow_color'] = "#000000"; // Image shadow background color for a 3D look (html style). Default black. 20 $f2i_array['background_shadow_width'] = 0; // Width of the background shadow of the image. Default = 0, Max = 10. 21 $f2i_array['outline_color'] = ""; // Outline color (html style). If not specified, width is set to 0. 22 $f2i_array['outline_width'] = 0; // Width of the outline of the character in pixels. Default = 0, Max = 10. 23 $f2i_array['shadow_color'] = ""; // Shadow color (html style). If not specified, width is set to 0. 24 $f2i_array['shadow_width'] = 0; // Width of the shadow of the character in pixels. Default = 0, Max = 10. 25 $f2i_array['background_transparent'] = false; // Should the background color be marked transparent? Boolean, default = false; 26 $f2i_array['background_transparent_color'] = ""; // Optional. If defined, this color will be used for transparancy instead of 27 // the specified background color. Required if a background shadow is defined 28 $f2i_array['cache_images'] = false; // Cache the image after generation? Boolean, default = false. 29 $f2i_array['cache_folder'] = ""; // Directory to store the cached images in. 30 // If not defined or not valid, cache_images will be set to false. 31 $f2i_array['cache_prefix'] = false; // If defined, this will be prepended to the filename of the cached file 32 $f2i_array['cache_hash'] = false; // Boolean. If false, the text will be used as filename, otherwise a hash is calculated 33 $f2i_array['return_link'] = false; // If true, the function returns a relative link to the cached image instead of the 34 // image itself. If true, cache_images MUST be set to true as well!!! 35 36 Notes: 37 * if the background has a shadow, background transparency is used to create the 3D effect. The text background 38 itself can therefore not be transparent. 38 39 39 40 */ 40 if ( !defined("INIT_CMS_OK")) { header("Location: ../index.php"); exit; }41 if (eregi("font2image.php", $_SERVER['PHP_SELF']) || !defined('INIT_CMS_OK')) die(); 41 42 42 43 function font2image($font2image) { … … 93 94 if (!isset($font2image['background_transparent'])) $font2image['background_transparent'] = false; 94 95 if (!isset($font2image['cache_images'])) $font2image['cache_images'] = false; 96 if (!isset($font2image['return_link'])) $font2image['return_link'] = false; 95 97 if (!isset($font2image['cache_folder'])) $font2image['cache_images'] = false; 96 if ($font2image['cache_folder'] !="" && !is_dir($font2image['cache_folder'])) fatal_error( 'Cache folder does not exist.');98 if ($font2image['cache_folder'] !="" && !is_dir($font2image['cache_folder'])) fatal_error("Cache folder does not exist."); 97 99 if (!isset($font2image['cache_prefix']) || $font2image['cache_prefix'] == false) $font2image['cache_prefix'] = ""; 98 100 if (!isset($font2image['cache_hash'])) $font2image['cache_hash'] = false; 101 if ($font2image['return_link'] && !$font2image['cache_images']) fatal_error("Can't link without cache."); 99 102 100 103 if (!isset($font2image['font_spacing'])) $font2image['font_spacing'] = false; … … 121 124 } 122 125 126 // Create the filename for this image, use hash if requested 127 if ($font2image['cache_hash']) { 128 $hash = ""; 129 foreach ($font2image as $element) { 130 $hash .= $element; 131 } 132 $hash = md5($hash); 133 } else { 134 $hash = str_replace(' ', '_', $font2image['font_text']); 135 } 136 $cache_filename = $font2image['cache_folder'] . '/' . $font2image['cache_prefix'] . $hash . '.' . $font2image['image'] ; 137 123 138 // Do we have caching enabled for this image? 124 139 if ($font2image['cache_images']) { 125 140 // look for cached copy, if it exists, convert it to a resource and return it 126 if ($font2image['cache_hash']) {127 $hash = "";128 foreach ($font2image as $element) {129 $hash .= $element;130 }131 $hash = md5($hash);132 } else {133 $hash = str_replace(' ', '_', $font2image['font_text']);134 }135 $cache_filename = $font2image['cache_folder'] . '/' . $font2image['cache_prefix'] . $hash . '.' . $font2image['image'] ;136 141 if($font2image['cache_images'] && is_readable($cache_filename)) { 137 142 // convert the file to a resource … … 140 145 fatal_error("Cached image file '".$cache_filename."' is not a valid ".strtoupper($font2image['image'])." image!"); 141 146 } 142 switch ($font2image['image']) { 143 case "png": 144 $image = imagecreatefrompng($cache_filename); 145 break; 146 case "jpg": 147 $image = imagecreatefromjpeg($cache_filename); 148 break; 149 case "gif": 150 $image = imagecreatefromgif($cache_filename); 151 break; 147 if ($font2image['return_link']) { 148 // check if the cache path is inside the webroot 149 if (substr($cache_filename,0,strlen(PATH_ROOT)) != PATH_ROOT) { 150 fatal_error("Cached image is not inside the webroot!"); 151 } else { 152 return substr($cache_filename, strlen(PATH_ROOT)-1); 153 } 154 } else { 155 switch ($font2image['image']) { 156 case "png": 157 $image = imagecreatefrompng($cache_filename); 158 break; 159 case "jpg": 160 $image = imagecreatefromjpeg($cache_filename); 161 break; 162 case "gif": 163 $image = imagecreatefromgif($cache_filename); 164 break; 165 } 166 return $image; 152 167 } 153 return $image;154 168 } 155 169 } … … 182 196 fatal_error('The server could not create this image.') ; 183 197 } 184 185 198 // give the image a background color 186 199 if (isset($font2image['background_transparent_color'])) { … … 191 204 $font2image['background_transparent_color'] = @ImageColorAllocate($image, $background_rgb['red'], $background_rgb['green'], $background_rgb['blue']) ; 192 205 imagefill($image, 0,0, $font2image['background_transparent_color']); 206 // set transparency 207 if ($font2image['background_transparent']) { 208 ImageColorTransparent($image, $font2image['background_transparent_color']) ; 209 } 210 // background color and background shadow color 193 211 $background_rgb = hex_to_rgb($font2image['background_shadow_color']) ; 194 212 $font2image['background_shadow_color'] = @ImageColorAllocate($image, $background_rgb['red'], $background_rgb['green'], $background_rgb['blue']) ; … … 250 268 } 251 269 252 // set transparency253 if ($font2image['background_transparent']) {254 ImageColorTransparent($image, $font2image['background_transparent_color']) ;255 }256 257 270 // write it to the cache directory if needed 258 271 if ($font2image['cache_images']) { … … 269 282 } 270 283 } 271 // imagePNG($image);die(); 272 return $image; 284 if ($font2image['return_link']) { 285 // check if the cache path is inside the webroot 286 if (substr($cache_filename,0,strlen(PATH_ROOT)) != PATH_ROOT) { 287 fatal_error("Cached image is not inside the webroot!"); 288 } else { 289 return substr($cache_filename, strlen(PATH_ROOT)-1); 290 } 291 } else { 292 return $image; 293 } 273 294 } 274 295
Note: See TracChangeset
for help on using the changeset viewer.
