Last active
August 29, 2015 14:21
-
-
Save Der-Eddy/9bf39b5ce29d9b6c9fa4 to your computer and use it in GitHub Desktop.
RocketBeansTV Twitch Thumbnail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$channelname = "rocketbeanstv"; | |
$height = 300; | |
$width = 164; | |
$font = 4; //1 bis 5 gültig | |
$path_file = dirname(__FILE__) . "/thumbnail.jpg"; | |
$path = basename($path_file); | |
$text_alt = array("Der erste 24/7 Sender auf Twitch", "Lust mal wieder auf GIGA Stimmung?", "Rocketbeans.tv Live Twitch Stream", "GameOne abgesetzt? Hier gehts weiter!", "Eduard Laser!"); | |
$text_filler = array("Nachtprogramm", "Feiertag!", "Wochenende!"); | |
$stream = json_decode(get_url_contents("https://api.twitch.tv/kraken/streams/$channelname/")); | |
//$text = $stream->stream->game; //Aktuelles Spiel | |
$text = $stream->stream->channel->status; // Aktuelle Twitch Stream Überschrift | |
if(in_array($text, $text_filler)){ | |
$text = $text_alt[array_rand($text_alt)]; | |
} | |
$img = imagecreatefromjpeg("http://static-cdn.jtvnw.net/previews-ttv/live_user_" . $channelname . "-" . $height . "x" . $width .".jpg"); | |
$wmwidth = imagefontwidth($font) * strlen($text); | |
$wmheight = imagefontheight($font); | |
$wm = imagecreate ($wmwidth, $wmheight); | |
imagecolorallocate ($wm, 222, 222, 222); | |
ImageString ($wm, $font, 0, 0, $text, ImageColorAllocate($wm, 0, 0, 0)); | |
imagecopymerge($img, $wm, imagesx($img) - imagesx($wm), imagesy($img) - imagesy($wm), 0, 0, $wmwidth, $wmheight, 70); | |
imagejpeg ($img, $path_file); | |
imagedestroy($img); | |
imagedestroy($wm); | |
echo "<img src=\"$path\">"; | |
//Das Bild wird mit Absicht nicht direkt ausgegeben | |
function get_url_contents($url){ | |
$crl = curl_init(); | |
$timeout = 5; | |
curl_setopt ($crl, CURLOPT_URL,$url); | |
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
$ret = curl_exec($crl); | |
curl_close($crl); | |
return $ret; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment