/testfolders/max/V1.2/PHP/generate_header.php

https://bitbucket.org/mh268408/infofigures · PHP · 510 lines · 378 code · 63 blank · 69 comment · 130 complexity · f9f6f6c3551dfe12ec53fa1051c5faf0 MD5 · raw file

  1. <?php
  2. //libraries
  3. require_once("gradient-fill.php"); //needed to make the gradients
  4. require_once("colors.php"); //pallet and size data
  5. //variables
  6. $pallet = $_POST['pallet'];
  7. $size = $_POST['size'];
  8. $title = $_POST['title'];
  9. $title = str_replace("\'", "'", $title);
  10. $title = str_replace('\"', '"', $title);
  11. $author=$_POST['author'];
  12. $author = str_replace("\'", "'", $author);
  13. $author = str_replace('\"', '"', $author);
  14. $description = $_POST['description'];
  15. $description = str_replace("\'", "'", $description);
  16. $description = str_replace('\"', '"', $description);
  17. $layout = $_POST['layout'];
  18. $font = $_POST['font'];
  19. $author_font_size = 18;
  20. $title_font_size = 50;
  21. $description_font_size = 10;
  22. $description_max_len = 50;
  23. switch($size){
  24. case "small": $width = $small;
  25. break;
  26. case "medium": $width = $medium;
  27. break;
  28. case "large": $width = $large;
  29. break;
  30. }
  31. foreach($pallets_html as $key => $html){
  32. if($html[0] == $pallet){
  33. $bgcolor_reference = $pallets_text[$key][0];
  34. $main_header_color_ref = $pallets_text[$key][1];
  35. $sub_header_color_ref = $pallets_text[$key][2];
  36. $body_text_color_ref = $pallets_text[$key][3];
  37. }
  38. }
  39. foreach($fonts as $current){
  40. if($current[2] == $font)
  41. $font_path = $current[0];
  42. }
  43. if($font_path == null)
  44. $font_path = "../fonts/arial.ttf";
  45. if($bgcolor_reference == null){
  46. $bgcolor_reference = $black_on_white_text[0];
  47. $main_header_color_ref = $black_on_white_text[1];
  48. $sub_header_color_ref = $black_on_white_text[2];
  49. $body_text_color_ref = $black_on_white_text[3];
  50. }
  51. if($width == null || $width == 'n/a')
  52. $width = "800";
  53. /*
  54. switch($pallet){
  55. case "underground": $bgcolor_reference = $underground_text[0];
  56. $main_header_color_ref = $underground_text[1];
  57. $sub_header_color_ref = $underground_text[2];
  58. $body_text_color_ref = $underground_text[3];
  59. break;
  60. case "clownfish": $bgcolor_reference = $clownfish_text[0];
  61. $main_header_color_ref = $clownfish_text[1];
  62. $sub_header_color_ref = $clownfish_text[2];
  63. $body_text_color_ref = $clownfish_text[3];
  64. break;
  65. case "wine": $bgcolor_reference = $wine_text[0];
  66. $main_header_color_ref = $wine_text[1];
  67. $sub_header_color_ref = $wine_text[2];
  68. $body_text_color_ref = $wine_text[3];
  69. break;
  70. case "dribble": $bgcolor_reference = $dribble_text[0];
  71. $main_header_color_ref = $dribble_text[1];
  72. $sub_header_color_ref = $dribble_text[2];
  73. $body_text_color_ref = $dribble_text[3];
  74. break;
  75. case "black_on_white": $bgcolor_reference = $black_on_white_text[0];
  76. $main_header_color_ref = $black_on_white_text[1];
  77. $sub_header_color_ref = $black_on_white_text[2];
  78. $body_text_color_ref = $black_on_white_text[3];
  79. break;
  80. case "white_on_black": $bgcolor_reference = $white_on_black_text[0];
  81. $main_header_color_ref = $white_on_black_text[1];
  82. $sub_header_color_ref = $white_on_black_text[2];
  83. $body_text_color_ref = $white_on_black_text[3];
  84. break;
  85. }
  86. */
  87. $bgcolor_referencergb = hex2rgb($bgcolor_reference);
  88. $main_header_color_ref_rgb = hex2rgb($main_header_color_ref);
  89. $sub_header_color_ref_rgb = hex2rgb($sub_header_color_ref);
  90. $body_text_color_ref_rgb = hex2rgb($body_text_color_ref);
  91. if($bgcolor_referencergb[0] + 50 > 255)
  92. $bgcolor_referencergb[0] = 255;
  93. else
  94. $bgcolor_referencergb[0]=$bgcolor_referencergb[0]+50;
  95. if($bgcolor_referencergb[1] + 50 > 255)
  96. $bgcolor_referencergb[1] = 255;
  97. else
  98. $bgcolor_referencergb[1]=$bgcolor_referencergb[1]+50;
  99. if($bgcolor_referencergb[2] + 50 > 255)
  100. $bgcolor_referencergb[2] = 255;
  101. else
  102. $bgcolor_referencergb[2]=$bgcolor_referencergb[2]+50;
  103. $color2=rgb2hex($bgcolor_referencergb);
  104. $gradient_spawn = new gd_gradient_fill($width,100,'vertical',$color2,$bgcolor_reference);
  105. $bgcolor_referencergb = hex2rgb($bgcolor_reference);
  106. //Create background and copy it to the gradient
  107. $gradient = imagecreatefrompng('gradient.png');
  108. $background = imagecreate($width, 300);
  109. $backgroundcolor = imagecolorallocate($background, $bgcolor_referencergb[0], $bgcolor_referencergb[1], $bgcolor_referencergb[2]);
  110. $bgcolor = imagecolorallocate($background, $bgcolor_reference_explode[0], $bgcolor_reference_explode[1], $bgcolor_reference_explode[2]);
  111. imagecopymerge($background, $gradient, 0, 0, 0, 0, $width, 100, 100);
  112. $main_header_color = imagecolorallocate($background, $main_header_color_ref_rgb[0], $main_header_color_ref_rgb[1], $main_header_color_ref_rgb[2]);
  113. $sub_header_color = imagecolorallocate($background, $sub_header_color_ref_rgb[0], $sub_header_color_ref_rgb[1], $sub_header_color_ref_rgb[2]);
  114. $body_text_color = imagecolorallocate($background, $body_text_color_ref_rgb[0], $body_text_color_ref_rgb[1], $body_text_color_ref_rgb[2]);
  115. if($layout == 'one'){
  116. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  117. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  118. if($bboxWidth > 150){
  119. while($bboxWidth > 150){
  120. $author_font_size-=1;
  121. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  122. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  123. }
  124. }
  125. else{
  126. while($bboxWidth < 150){
  127. $author_font_size+=1;
  128. if((abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1) > 20)
  129. break;
  130. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  131. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  132. }
  133. }
  134. $authorHeight=abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1;
  135. imagettftext($background, $author_font_size, 0, $width-160, $authorHeight+10, $sub_header_color, $font_path, $author);
  136. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  137. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  138. if($bboxWidth > $width-50){
  139. while($bboxWidth > $width-50){
  140. $title_font_size-=1;
  141. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  142. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  143. }
  144. }
  145. else{
  146. while($bboxWidth < $width-50){
  147. $title_font_size+=1;
  148. if((abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1) > 100)
  149. break;
  150. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  151. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  152. }
  153. }
  154. $titleHeight=abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1;
  155. imagettftext($background, $title_font_size, 0, 10, $authorHeight+$titleHeight+20, $main_header_color, $font_path, $title);
  156. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  157. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  158. if($bboxWidth > $width-30){
  159. while($bboxWidth > $width-30){
  160. $description_max_len-=1;
  161. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  162. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  163. }
  164. }
  165. else{
  166. while($bboxWidth < $width-30){
  167. if(strlen($description) < $description_max_len)
  168. break;
  169. else{
  170. $description_max_len+=1;
  171. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  172. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  173. }
  174. }
  175. }
  176. if(strlen($description) <= $description_max_len){
  177. imagettftext($background, $description_font_size, 0, 10, $authorHeight+$titleHeight+30+$description_font_size, $body_text_color, $font_path, $description); $lines = 1;
  178. }
  179. else{
  180. //line 1
  181. $description_buffer = substr($description, 0, $description_max_len); $lines = 1;
  182. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len] != ' ' && strlen($description) > $description_max_len)
  183. $description_buffer = $description_buffer . "-";
  184. imagettftext($background, $description_font_size, 0, 10, $authorHeight+$titleHeight+30+$description_font_size, $body_text_color, $font_path, $description_buffer);
  185. //Line 2
  186. $description_buffer = substr($description, $description_max_len, $description_max_len);
  187. if(strlen($description_buffer) != 0) $lines=2;
  188. if($description_buffer[0] == ' ')
  189. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  190. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*2] != ' ' && $description_max_len*2 < strlen($description))
  191. $description_buffer = $description_buffer . "-";
  192. imagettftext($background, $description_font_size, 0, 10, $authorHeight+$titleHeight+40+$description_font_size*2, $body_text_color, $font_path, $description_buffer);
  193. //Line 3
  194. $description_buffer = substr($description, $description_max_len*2, $description_max_len);
  195. if(strlen($description_buffer) != 0) $lines=3;
  196. if($description_buffer[0] == ' ')
  197. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  198. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*3] != ' ' && $description_max_len*3 < strlen($description))
  199. $description_buffer = $description_buffer . "-";
  200. imagettftext($background, $description_font_size, 0, 10, $authorHeight+$titleHeight+50+$description_font_size*3, $body_text_color, $font_path, $description_buffer);
  201. //Line 4
  202. $description_buffer = substr($description, $description_max_len*3, $description_max_len);
  203. if(strlen($description_buffer) != 0) $lines=4;
  204. if($description_buffer[0] == ' ')
  205. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  206. imagettftext($background, $description_font_size, 0, 10, $authorHeight+$titleHeight+60+$description_font_size*4, $body_text_color, $font_path, $description_buffer);
  207. }
  208. $final=imagecreatetruecolor($width, $authorHeight+$titleHeight+20+(10*$lines)+$description_font_size*$lines+15);
  209. imagecopyresampled($final, $background, 0, 0, 0, 0, $width, 300, $width, 300);
  210. }
  211. else if ($layout == 'two'){
  212. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  213. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  214. if($bboxWidth > $width-50){
  215. while($bboxWidth > $width-50){
  216. $title_font_size-=1;
  217. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  218. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  219. }
  220. }
  221. else{
  222. while($bboxWidth < $width-50){
  223. $title_font_size+=1;
  224. if((abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1) > 100)
  225. break;
  226. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  227. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  228. }
  229. }
  230. $titleHeight=abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1;
  231. $x = $bbox[0] + (imagesx($background) / 2) - ($bbox[4] / 2) - 5;
  232. // Write it
  233. imagettftext($background, $title_font_size, 0, $x, $titleHeight+10, $main_header_color, $font_path, $title);
  234. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  235. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  236. if($bboxWidth > $width*0.75){
  237. while($bboxWidth > $width*0.75){
  238. $author_font_size-=1;
  239. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  240. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  241. }
  242. }
  243. else{
  244. while($bboxWidth < $width*0.75){
  245. $author_font_size+=1;
  246. if((abs(min(array($bbox[1],$bbox[3],$bbox[5],$bbox[7]))) - 1) > 25)
  247. break;
  248. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  249. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  250. }
  251. }
  252. $authorHeight=abs(min(array($bbox[1],$bbox[3],$bbox[5],$bbox[7]))) - 1;
  253. $x = $bbox[0] + (imagesx($background) / 2) - ($bbox[4] / 2) - 5;
  254. imageline($background, $x+10, $authorHeight+$titleHeight+25, $x+$bboxWidth-10, $authorHeight+$titleHeight+25, $sub_header_color);
  255. // Write it
  256. imagettftext($background, $author_font_size, 0, $x, $titleHeight+$authorHeight+20, $sub_header_color, $font_path, $author);
  257. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  258. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  259. if($bboxWidth > $width-70){
  260. while($bboxWidth > $width-70){
  261. $description_max_len-=1;
  262. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  263. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  264. }
  265. }
  266. else{
  267. while($bboxWidth < $width-70){
  268. if(strlen($description) < $description_max_len)
  269. break;
  270. else{
  271. $description_max_len+=1;
  272. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  273. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  274. }
  275. }
  276. }
  277. //Line 1
  278. $description_buffer = substr($description, 0, $description_max_len);
  279. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len] != ' ' && strlen($description) > $description_max_len)
  280. $description_buffer = $description_buffer . "-";
  281. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  282. // This is our cordinates for X and Y
  283. $x = $bbox[0] + (imagesx($background) / 2) - ($bbox[4] / 2) - 5;
  284. $description_y = $titleHeight+$authorHeight+$description_font_size+30;
  285. // Write it
  286. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  287. //Line 2
  288. $description_buffer = substr($description, $description_max_len, $description_max_len);
  289. if($description_buffer[0] == ' ')
  290. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  291. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*2] != ' ' && $description_max_len*2 < strlen($description))
  292. $description_buffer = $description_buffer . "-";
  293. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  294. // This is our cordinates for X and Y
  295. $x = $bbox[0] + (imagesx($background) / 2) - ($bbox[4] / 2) - 5;
  296. if(strlen($description_buffer) != 0) $description_y+=$description_font_size+10;
  297. // Write it
  298. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  299. //Line 3
  300. $description_buffer = substr($description, $description_max_len*2, $description_max_len);
  301. if($description_buffer[0] == ' ')
  302. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  303. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*3] != ' ' && $description_max_len*3 < strlen($description))
  304. $description_buffer = $description_buffer . "-";
  305. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  306. // This is our cordinates for X and Y
  307. $x = $bbox[0] + (imagesx($background) / 2) - ($bbox[4] / 2) - 5;
  308. if(strlen($description_buffer) != 0) $description_y+=$description_font_size+10;
  309. // Write it
  310. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  311. //Line 4
  312. $description_buffer = substr($description, $description_max_len*3, $description_max_len);
  313. if($description_buffer[0] == ' ')
  314. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  315. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*4] != ' ' && $description_max_len*4 < strlen($description))
  316. $description_buffer = $description_buffer . "-";
  317. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  318. // This is our cordinates for X and Y
  319. $x = $bbox[0] + (imagesx($background) / 2) - ($bbox[4] / 2) - 5;
  320. if(strlen($description_buffer) != 0) $description_y+=$description_font_size+10;
  321. // Write it
  322. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  323. $final=imagecreatetruecolor($width, $description_y+15);
  324. imagecopyresampled($final, $background, 0, 0, 0, 0, $width, 300, $width, 300);
  325. }
  326. else{
  327. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  328. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  329. if($bboxWidth > $width*0.35){
  330. while($bboxWidth > $width*0.35){
  331. $title_font_size-=1;
  332. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  333. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  334. }
  335. }
  336. else{
  337. while($bboxWidth < $width*0.35){
  338. $title_font_size+=1;
  339. if((abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1) > 100)
  340. break;
  341. $bbox = imagettfbbox($title_font_size, 0, $font_path, $title);
  342. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  343. }
  344. }
  345. $titleHeight=abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1;
  346. $titleWidth = $bboxWidth + 20;
  347. // Write it
  348. imagettftext($background, $title_font_size, 0, 10, $titleHeight+10, $main_header_color, $font_path, $title);
  349. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  350. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  351. if($bboxWidth > $width*0.2){
  352. while($bboxWidth > $width*0.2){
  353. $author_font_size-=1;
  354. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  355. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  356. }
  357. }
  358. else{
  359. while($bboxWidth < $width*0.2){
  360. $author_font_size+=1;
  361. if((abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1) > 25)
  362. break;
  363. $bbox = imagettfbbox($author_font_size, 0, $font_path, $author);
  364. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  365. }
  366. }
  367. $authorHeight=abs(min(array($bbox[2],$bbox[3],$bbox[5],$bbox[7]))) - 1;
  368. // Write it
  369. imagettftext($background, $author_font_size, 0, 10, $titleHeight+$authorHeight+20, $sub_header_color, $font_path, $author);
  370. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  371. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  372. if($bboxWidth > $width*0.60){
  373. while($bboxWidth > $width*0.60){
  374. $description_max_len-=1;
  375. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  376. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  377. }
  378. }
  379. else{
  380. while($bboxWidth < $width*0.60){
  381. if(strlen($description) < $description_max_len)
  382. break;
  383. else{
  384. $description_max_len+=1;
  385. $bbox = imagettfbbox($description_font_size, 0, $font_path, substr($description, 0, $description_max_len));
  386. $bboxWidth= max(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]))-min(array($bbox[0],$bbox[2],$bbox[4],$bbox[6]));
  387. }
  388. }
  389. }
  390. //Line 1
  391. $description_buffer = substr($description, 0, $description_max_len);
  392. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len] != ' ' && strlen($description) > $description_max_len)
  393. $description_buffer = $description_buffer . "-";
  394. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  395. // This is our cordinates for X and Y
  396. $x = $titleWidth;
  397. $description_y = $description_font_size + 10;
  398. // Write it
  399. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  400. //Line 2
  401. $description_buffer = substr($description, $description_max_len, $description_max_len);
  402. if($description_buffer[0] == ' ')
  403. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  404. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*2] != ' ' && $description_max_len*2 < strlen($description))
  405. $description_buffer = $description_buffer . "-";
  406. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  407. // This is our cordinates for X and Y
  408. $x = $titleWidth;
  409. if(strlen($description_buffer) != 0) $description_y+=$description_font_size+10;
  410. // Write it
  411. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  412. //Line 3
  413. $description_buffer = substr($description, $description_max_len*2, $description_max_len);
  414. if($description_buffer[0] == ' ')
  415. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  416. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*3] != ' ' && $description_max_len*3 < strlen($description))
  417. $description_buffer = $description_buffer . "-";
  418. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  419. // This is our cordinates for X and Y
  420. $x = $titleWidth;
  421. if(strlen($description_buffer) != 0) $description_y+=$description_font_size+10;
  422. // Write it
  423. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  424. //Line 4
  425. $description_buffer = substr($description, $description_max_len*3, $description_max_len);
  426. if($description_buffer[0] == ' ')
  427. $description_buffer = substr($description_buffer, 1, $description_max_len-1);
  428. if($description_buffer[$description_max_len-1] != ' ' && $description[$description_max_len*4] != ' ' && $description_max_len*4 < strlen($description))
  429. $description_buffer = $description_buffer . "-";
  430. $bbox = imagettfbbox($description_font_size, 0, $font_path, $description_buffer);
  431. // This is our cordinates for X and Y
  432. $x = $titleWidth;
  433. if(strlen($description_buffer) != 0) $description_y+=$description_font_size+10;
  434. // Write it
  435. imagettftext($background, $description_font_size, 0, $x, $description_y, $body_text_color, $font_path, $description_buffer);
  436. $finalHeight = max(array($titleHeight+$authorHeight+35, $description_y+15));
  437. $final=imagecreatetruecolor($width, $finalHeight);
  438. imagecopyresampled($final, $background, 0, 0, 0, 0, $width, 300, $width, 300);
  439. }
  440. $x = 0;
  441. do{
  442. $x++;
  443. }while(file_exists($x.".png"));
  444. imagepng($final, $x.".png");
  445. header("Location: ../index.php?preview=true&size=" . $_POST['size'] . "&pallet=" . $_POST['pallet'] . "&layout=" . $_POST['layout'] . "&font=" . $_POST['font']);
  446. imagedestroy($gradient);
  447. ?>