Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $directory = '/var/ftp/ts/photos';
- $scanned_directory = array_diff(scandir($directory), array('..', '.', "background.jpg", "script.php"));
- $scanned_directory = array_values($scanned_directory);
- function csv_to_array($filename='', $delimiter=',')
- {
- if(!file_exists($filename) || !is_readable($filename))
- return FALSE;
- $header = NULL;
- $data = array();
- if (($handle = fopen($filename, 'r')) !== FALSE)
- {
- while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
- {
- if(!$header)
- $header = $row;
- else
- $data[] = array_combine($header, $row);
- }
- fclose($handle);
- }
- return $data;
- }
- /**
- * Example
- */
- $array = csv_to_array('data.csv');
- $max_sorrend = 30;
- $background_image = "background.jpg";
- //var_dump($array);
- $new_array = array();
- foreach ($array as $key => $value) {
- if ($key > 50 or $key == 50) {
- continue;
- }
- $new_array[$key] = $value;
- }
- var_dump($new_array);
- unset($new_array[48]);
- unset($new_array[49]);
- $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);
- $array_processed = array();
- foreach ($new_array as $key => $value) {
- //var_dump($value);
- $order = reset($value);
- $name = $value["Name"];
- $class_text = $value["Year"].$value["Class"];
- $title = $value["Production"];
- $order_order = $order - 1;
- if (!empty($array_processed[$order_order])) {
- continue;
- }
- //check whether they are in group
- if (array_key_exists($order, $array_gpd)) {
- echo $order;
- $how_much = $array_gpd[$order];
- if ($how_much == 3) {
- $key_new = $key + 1;
- $name_2 = $new_array[$key_new]["Name"];
- $class_text_2 = $new_array[$key_new]["Year"].$new_array[$key_new]["Class"];
- $key_new = $key + 2;
- $name_3 = $new_array[$key_new]["Name"];
- $class_text_3 = $new_array[$key_new]["Year"].$new_array[$key_new]["Class"];
- $size = 18;
- $text = $name." ".$class_text." & ".$name_2." ".$class_text_2." & ".$name_3." ".$class_text_3;
- } else {
- $key_new = $key + 1;
- $name_2 = $new_array[$key_new]["Name"];
- $class_text_2 = $new_array[$key_new]["Year"].$new_array[$key_new]["Class"];
- $size = 28;
- $text = $name." ".$class_text." & ".$name_2." ".$class_text_2;
- }
- } else {
- $size = 37;
- if (!empty($class_text)) {
- $text = $name." ".$class_text;
- } else {
- $text = $name;
- }
- }
- $IMG = imagecreatefrompng ("background.png");
- $white = imagecolorallocate($IMG, 238, 232, 53);
- $background = imagecolorallocate($IMG, 0,0,255);
- // Replace path by your own font path
- $font = '/var/ftp/ts/photos/arial.ttf';
- // Add the text
- //$standard = 420;
- //$standard_y = 90;
- if ($order == 9 or $order == 10 or $order == 19) {
- $size = 24;
- if ($order == 10) {
- $size = 22;
- }
- }
- if (is_file($order.".png") and $order !== 18 and $order !== 28) {
- $temp = imagecreatefrompng($order.".png");
- $w = imagesx($temp);
- $h = imagesy($temp);
- $def = 25;
- if ($order == 20 or $order == 28) {
- $def = 50;
- }
- if ($order !== 18 and $order !== 28) {
- imagecopyresampled($IMG, $temp, 200, $def, 0, 0, 960, 640, $w, $h);
- }
- /*
- 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 )
- 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 )
- */
- // Merge the red image onto the PNG image
- // imagecopy($IMG, $temp, 30, 30, 30, 30, $h, $w);
- }
- imagealphablending( $IMG, true );
- imagesavealpha( $IMG, true );
- imagettftext($IMG, 100, 0, 20, 120, $white, $font, "NEXT:");
- imagettftext($IMG, $size, 0,420, 80, $white, $font, $text);
- imagettftext($IMG, $size, 0,420, 130, $white, $font, $title);
- imagepng($IMG, $order."_final.png", 0);
- imagecolordeallocate($IMG, $background );
- imagecolordeallocate($IMG, $white);
- imagedestroy($IMG);
- $array_processed[] = $order;
- }
- /*
- $your_text = "Next: Raphael Bulay - S2FRC - Mad World";
- $IMG = imagecreatefrompng ("background.png");
- $background = imagecolorallocate($IMG, 0,0,255);
- $text_color = imagecolorallocate($IMG, 255,255,255);
- imagestring( $IMG, 10, 1, 25, $your_text, $text_color );
- imagepng($IMG, "test.png");
- imagecolordeallocate($IMG, $text_color );
- imagecolordeallocate($IMG, $background );
- imagedestroy($IMG);
- exit;
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement