Advertisement
Guest User

Untitled

a guest
May 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $directory = '/var/ftp/ts/photos';
  5. $scanned_directory = array_diff(scandir($directory), array('..', '.', "background.jpg", "script.php"));
  6. $scanned_directory = array_values($scanned_directory);
  7.  
  8.  
  9. function csv_to_array($filename='', $delimiter=',')
  10. {
  11. if(!file_exists($filename) || !is_readable($filename))
  12. return FALSE;
  13.  
  14. $header = NULL;
  15. $data = array();
  16. if (($handle = fopen($filename, 'r')) !== FALSE)
  17. {
  18. while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
  19. {
  20. if(!$header)
  21. $header = $row;
  22. else
  23. $data[] = array_combine($header, $row);
  24. }
  25. fclose($handle);
  26. }
  27. return $data;
  28. }
  29. /**
  30. * Example
  31. */
  32. $array = csv_to_array('data.csv');
  33. $max_sorrend = 30;
  34. $background_image = "background.jpg";
  35.  
  36. //var_dump($array);
  37. $new_array = array();
  38. foreach ($array as $key => $value) {
  39. if ($key > 50 or $key == 50) {
  40. continue;
  41. }
  42.  
  43. $new_array[$key] = $value;
  44. }
  45. var_dump($new_array);
  46. unset($new_array[48]);
  47. unset($new_array[49]);
  48. $array_gpd = array(2=>3, 6=>2, 8=>3, 9=>2, 10=>2, 11=>2, 13=>3, 15=>2, 17 => 3, 18 => 2, 19 => 2, 26=>2, 27 => 2, 28 => 2);
  49. $array_processed = array();
  50. foreach ($new_array as $key => $value) {
  51. //var_dump($value);
  52. $order = reset($value);
  53. $name = $value["Name"];
  54. $class_text = $value["Year"].$value["Class"];
  55. $title = $value["Production"];
  56.  
  57. $order_order = $order - 1;
  58. if (!empty($array_processed[$order_order])) {
  59. continue;
  60. }
  61.  
  62.  
  63.  
  64. //check whether they are in group
  65. if (array_key_exists($order, $array_gpd)) {
  66. echo $order;
  67. $how_much = $array_gpd[$order];
  68. if ($how_much == 3) {
  69. $key_new = $key + 1;
  70. $name_2 = $new_array[$key_new]["Name"];
  71. $class_text_2 = $new_array[$key_new]["Year"].$new_array[$key_new]["Class"];
  72. $key_new = $key + 2;
  73. $name_3 = $new_array[$key_new]["Name"];
  74. $class_text_3 = $new_array[$key_new]["Year"].$new_array[$key_new]["Class"];
  75.  
  76. $size = 18;
  77. $text = $name." ".$class_text." & ".$name_2." ".$class_text_2." & ".$name_3." ".$class_text_3;
  78.  
  79.  
  80. } else {
  81. $key_new = $key + 1;
  82. $name_2 = $new_array[$key_new]["Name"];
  83. $class_text_2 = $new_array[$key_new]["Year"].$new_array[$key_new]["Class"];
  84.  
  85.  
  86. $size = 28;
  87. $text = $name." ".$class_text." & ".$name_2." ".$class_text_2;
  88.  
  89. }
  90.  
  91. } else {
  92. $size = 37;
  93. if (!empty($class_text)) {
  94. $text = $name." ".$class_text;
  95. } else {
  96. $text = $name;
  97. }
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. $IMG = imagecreatefrompng ("background.png");
  106. $white = imagecolorallocate($IMG, 238, 232, 53);
  107. $background = imagecolorallocate($IMG, 0,0,255);
  108.  
  109.  
  110. // Replace path by your own font path
  111. $font = '/var/ftp/ts/photos/arial.ttf';
  112.  
  113. // Add the text
  114.  
  115. //$standard = 420;
  116. //$standard_y = 90;
  117.  
  118. if ($order == 9 or $order == 10 or $order == 19) {
  119. $size = 24;
  120. if ($order == 10) {
  121. $size = 22;
  122. }
  123. }
  124.  
  125. if (is_file($order.".png") and $order !== 18 and $order !== 28) {
  126.  
  127. $temp = imagecreatefrompng($order.".png");
  128. $w = imagesx($temp);
  129. $h = imagesy($temp);
  130. $def = 25;
  131. if ($order == 20 or $order == 28) {
  132. $def = 50;
  133. }
  134. if ($order !== 18 and $order !== 28) {
  135. imagecopyresampled($IMG, $temp, 200, $def, 0, 0, 960, 640, $w, $h);
  136. }
  137.  
  138. /*
  139. bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
  140.  
  141. bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
  142. */
  143. // Merge the red image onto the PNG image
  144. // imagecopy($IMG, $temp, 30, 30, 30, 30, $h, $w);
  145. }
  146.  
  147. imagealphablending( $IMG, true );
  148. imagesavealpha( $IMG, true );
  149.  
  150. imagettftext($IMG, 100, 0, 20, 120, $white, $font, "NEXT:");
  151. imagettftext($IMG, $size, 0,420, 80, $white, $font, $text);
  152. imagettftext($IMG, $size, 0,420, 130, $white, $font, $title);
  153.  
  154. imagepng($IMG, $order."_final.png", 0);
  155. imagecolordeallocate($IMG, $background );
  156. imagecolordeallocate($IMG, $white);
  157. imagedestroy($IMG);
  158.  
  159. $array_processed[] = $order;
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. }
  167. /*
  168. $your_text = "Next: Raphael Bulay - S2FRC - Mad World";
  169.  
  170. $IMG = imagecreatefrompng ("background.png");
  171. $background = imagecolorallocate($IMG, 0,0,255);
  172. $text_color = imagecolorallocate($IMG, 255,255,255);
  173. imagestring( $IMG, 10, 1, 25, $your_text, $text_color );
  174. imagepng($IMG, "test.png");
  175. imagecolordeallocate($IMG, $text_color );
  176. imagecolordeallocate($IMG, $background );
  177. imagedestroy($IMG);
  178. exit;
  179. */
  180. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement