function set_font(&$obj, $fld) { if (isset($_GET[$fld])) { if (preg_match('/^(\\d\\d?)?(b|i|bi|ib)?(-|$)/', $_GET[$fld], $p)) { $s = $p[1]; if (!$s) { $s = 10; } $at = isset($p[2]) ? $p[2] : ''; if (strstr($at, 'b')) { $font = strstr($at, 'i') ? new TuffyBoldItalic($s) : new TuffyBold($s); } elseif (strstr($at, 'i')) { $font = new TuffyItalic($s); } else { $font = new Tuffy($s); } $obj->setFont($font, make_color($fld, '000000')); } else { $obj->setColor(make_color($fld, '000000')); } } }
$img_height = ceil(strlen($caption) * 8); $background_color = 'FFFFFF'; $font_color = 0; $font_size = 3; // Create color. function make_color($color) { global $img; $red = hexdec(substr($color, 0, 2)); $green = hexdec(substr($color, 2, 2)); $blue = hexdec(substr($color, 4, 2)); return imagecolorallocate($img, $red, $green, $blue); } // Sending header. header("Content-type: image/png"); /* * Creating image */ // Creating ressource. $img = imagecreate($img_width, $img_height); // Creating colors. $background_color_id = make_color($background_color); $font_color = make_color($font_color); // Writing text. imagestringup($img, $font_size, (int) ($img_width / 2 - $img_width / 3), $img_height - 3, $caption, $font_color); // Making image transparent. imagecolortransparent($img, $background_color_id); // Returning image. imagepng($img); // Freeing memory. imagedestroy($img);
// Find the 9th time "$search_for" occurs $pos = strposX($html, $search_for, 9 + 11 * $buoy_index); // Add on the lenght of "$search_for" get the position of its end $pos += strlen($search_for); // text is everything after "$search_for" e.g. text = " 0.4 </td" $text = substr($html, $pos, 15); if (strpos($text, 'n/a') !== false) { http_response_code(404); echo json_encode($error_response); exit; } // Get everythong before the "<" $period = trim(explode('<', $text)[0]); // Repeat for the 10th time $pos = strposX($html, $search_for, 10 + 11 * $buoy_index); // Add on the lenght of "$search_for" get the position of its end $pos += strlen($search_for); // text is everything after "$search_for" e.g. text = " 0.4 </td" $text = substr($html, $pos, 15); if (strpos($text, 'n/a') !== false) { http_response_code(404); echo json_encode($error_response); exit; } // Get everythong before the "<" $height = trim(explode('<', $text)[0]); $frequency = period_to_frequency($period); $volume = height_to_volume($height); $RGB = make_color($volume, $frequency); $response = array("frequency" => $frequency, "volume" => $volume, "color" => $RGB); echo json_encode($response);