function createCollage($covers, $quality, $totalSize, $cols, $rows, $albumInfo, $playcount)
{
    switch ($quality) {
        case 0:
            $pixels = 34;
            break;
        case 1:
            $pixels = 64;
            break;
        case 2:
            $pixels = 126;
            break;
        case 3:
            $pixels = 300;
            break;
    }
    //Create blank image
    $canvas = imagecreatetruecolor($pixels * $cols, $pixels * $rows);
    //Set black colour.
    $backgroundColor = imagecolorallocate($canvas, 0, 0, 0);
    //Fill with black
    imagefill($canvas, 0, 0, $backgroundColor);
    //Note where cursor is.
    $coords['x'] = 0;
    $coords['y'] = 0;
    $i = 1;
    //Grab images with cURL method.
    $images = getImages($covers);
    //For each image returned, create image object and write text
    foreach ($images as $rawdata) {
        error_log("Album Processing: " . $rawdata['artist'] . " - " . $rawdata['album']);
        $image = imagecreatefromstring($rawdata['data']);
        if ($albumInfo || $playcount) {
            $font = "resources/NotoSansCJK-Regular.ttc";
            $white = imagecolorallocate($image, 255, 255, 255);
            $black = imagecolorallocate($image, 0, 0, 0);
            if ($albumInfo && $playcount) {
                imagettfstroketext($image, 10, 0, 5, 20, $white, $black, $font, $rawdata['artist'], 1);
                imagettfstroketext($image, 10, 0, 5, 32, $white, $black, $font, $rawdata['album'], 1);
                imagettfstroketext($image, 10, 0, 5, 44, $white, $black, $font, "Plays: " . $rawdata['playcount'], 1);
            } elseif ($albumInfo) {
                imagettfstroketext($image, 10, 0, 5, 20, $white, $black, $font, $rawdata['artist'], 1);
                imagettfstroketext($image, 10, 0, 5, 32, $white, $black, $font, $rawdata['album'], 1);
            } elseif ($playcount) {
                imagettfstroketext($image, 10, 0, 5, 20, $white, $black, $font, "Plays: " . $rawdata['playcount'], 1);
            }
        }
        imagecopy($canvas, $image, $coords['x'], $coords['y'], 0, 0, $pixels, $pixels);
        //Increase X coords each time
        $coords['x'] += $pixels;
        //If we've hit the side of the image, move down and reset x position.
        if ($i % $cols == 0) {
            $coords['y'] += 300;
            $coords['x'] = 0;
        }
        $i++;
    }
    return $canvas;
}
示例#2
0
function meme_text($img, $text, $position, $lcrpos, $updown)
{
    global $ppath, $fontsize, $fontstrike, $fontfile, $offset;
    $font = $ppath . $fontfile;
    $bbox = imagettfbbox($fontsize, 0, $font, $text);
    $imgw = imagesx($img);
    $imgh = imagesy($img);
    $x = $bbox[0] + imagesx($img) / 2 - $bbox[4] / 2 - 100;
    $y = $bbox[1] + imagesy($img) / 2 - $bbox[5] / 2 - 5;
    $fw = abs($bbox[2] - $bbox[0]);
    $fh = abs($bbox[7] - $bbox[1]);
    $centerx = ($imgw - $fw) / 2;
    $centery = ($imgh + $fh) / 2;
    if ($lcrpos === 1) {
        $xx = $offset;
    } elseif ($lcrpos === 2) {
        $xx = $centerx;
    } elseif ($lcrpos === 3) {
        $xx = $imgw - $fw - $offset;
    }
    $yy = $position * ($fontsize + 2 * $fontstrike);
    $yy = $yy + (int) $updown * 3;
    /*switch( $position )
    	{
    		case 'top' : $yy = 20;break;
    		case 'bottom' : $yy = $imgh - $fh - 20;break;
    	}*/
    $positionx = $xx;
    $positiony = +$fh + +$yy;
    $col = imagecolorallocate($img, 250, 250, 250);
    $strokecol = imagecolorallocate($img, 25, 25, 25);
    imagettfstroketext($img, $fontsize, 0, $positionx, $positiony, $col, $strokecol, $font, $text, $fontstrike);
}
$colorWhite = imagecolorallocate($im, 255, 255, 255);
$colorBlack = imagecolorallocate($im, 0, 0, 0);
$colorGrey = imagecolorallocate($im, 130, 130, 130);
//border
//imagerectangle($im, 0, 0, $width - 1, $height - 1, $colorGrey);
for ($i = 0; $i < count($textRows); $i++) {
    //text size
    $line_box = imagettfbbox($fontSize, 0, $font, $textRows[$i]);
    $text_width = GetTextWidth($fontSize, $font, $textRows[$i]);
    $text_height = GetMaxTextHeight($fontSize, $font, $textRows) * 2.3;
    //align: center
    $position_center = ceil(($width - $text_width) / 2);
    //valign: middle
    $test = count($textRows) - $i - ceil(count($textRows) / 2);
    $position_middle = ceil(($height - $text_height * $test) / 2);
    imagettfstroketext($im, $fontSize, 0, $position_center, $position_middle, $colorBlack, $colorWhite, $font, $textRows[$i], 0);
}
// Inserting watermark at the end of text
$x = ceil(($width - 200) / 2);
$y = $position_middle + 10;
imagecopymerge($im, $watermark_im, $x, $y, 0, 0, 200, 37, 100);
//Image File Name
$file_name = "../../../Quotes/" . $ID . ".png";
imagepng($im, $file_name);
imagedestroy($im);
include 'connect.php';
$sqlUpdate = "UPDATE quotes SET STATUS = 1 WHERE ID = " . $ID;
if ($conn->query($sqlUpdate) === TRUE) {
    //echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
示例#4
0
    image_gradientrect($my_img, 0, 0, $img_w, $img_h, $img_c, $img_c2);
    image_gradientrect($my_img, $img_hp, 0, $img_w, $img_h, $img_bg, $img_bg2);
    //Border between "current" and "max" portions of HP bar
    imagesetthickness($my_img, 2);
    $line_color = imagecolorallocate($my_img, hexdec($img_ol[0]), hexdec($img_ol[1]), hexdec($img_ol[2]));
    imageline($my_img, $img_hp, 1, $img_hp, $img_h, $line_color);
    //Black borders ERRYWHERE
    imageline($my_img, 0, 1, $img_w, 1, $line_color);
    imageline($my_img, 0, $img_h - 1, $img_w, $img_h - 1, $line_color);
    imageline($my_img, 1, 0, 1, $img_h, $line_color);
    imageline($my_img, $img_w - 1, 0, $img_w - 1, $img_h, $line_color);
    //Setting up for text
    if (isset($_GET['text'])) {
        $font_color = imagecolorallocate($my_img, 255, 255, 255);
        $stroke_color = imagecolorallocate($my_img, 0, 0, 0);
        imagettfstroketext($my_img, 14, 0, 10, 27, $font_color, $stroke_color, "fonts/arial.ttf", $hp_cur . " / " . $hp_max, 2);
    }
    imagepng($my_img);
    header("Content-type: image/png");
    imagedestroy($my_img);
} else {
    $textblock = '<h1>HP_PNG</h1>
<p>HP_PNG is a $_GET-using, dynamic image creator designed for use with resource bars for PbP games.<br>
Available variables are as follows:</p>
<h2></span>"c":</h2>
<ul>
<li>The color of the HP bar, in RGB hex.  Defaults to <em>"00dd00"</em> (green)</li>
</ul>
<h2>"c2":</h2>
<ul>
<li>The secondary bottom color of the HP bar, in RGB hex. Darker version of "c" by default.</li>
示例#5
-1
function create_banner($lang, $file, $data)
{
    $movie_sql = 'SELECT `id`, `title`, `originaltitle`, `rating`, `runtime`, `year`, `last_played` FROM `movies` ORDER BY `last_played` DESC LIMIT 0, 1';
    $movie_result = mysql_q($movie_sql);
    $movie = mysql_fetch_assoc($movie_result);
    $episode_sql = 'SELECT `episode`, `season`, `tvshow`, `title`, `last_played` FROM `episodes` ORDER BY `last_played` DESC LIMIT 0, 1';
    $episode_result = mysql_q($episode_sql);
    $episode = mysql_fetch_assoc($episode_result);
    $episode['e_title'] = $episode['title'];
    unset($episode['title']);
    if (isset($episode['last_played']) && $episode['last_played'] > $movie['last_played']) {
        $tvshow_sql = 'SELECT `id`, `title`, `originaltitle`, `rating`, `last_played` FROM `tvshows` WHERE `id` = ' . $episode['tvshow'];
        $tvshow_result = mysql_q($tvshow_sql);
        $tvshow = mysql_fetch_assoc($tvshow_result);
        $ban = array_merge($tvshow, $episode);
        $table = 'tvshows';
        $panels_array = array('genre');
    } else {
        $ban = $movie;
        $table = 'movies';
        $panels_array = array('genre', 'country');
    }
    if (isset($ban['id'])) {
        foreach ($panels_array as $val) {
            $sel_sql = 'SELECT ' . $val . '.' . $val . ' FROM ' . $val . ', ' . $table . '_' . $val . ' WHERE ' . $val . '.id = ' . $table . '_' . $val . '.' . $val . 'id AND ' . $table . '_' . $val . '.id = "' . $ban['id'] . '"';
            $sel_res = mysql_q($sel_sql);
            $out = array();
            while ($s = mysql_fetch_row($sel_res)) {
                $out[] = $s[0];
            }
            $ban[$val] = implode(' / ', $out);
        }
    }
    $b = array();
    $b['w'] = 400;
    // banner width
    $b['h'] = 70;
    // banner height
    $b['bg_c'] = '141414';
    // background color
    $b['lw_c'] = 'FFFFFF';
    // last watched color
    $b['lw_s'] = 10;
    // last watched font size
    $b['lw_x'] = 130;
    // last watched pos. x
    $b['lw_y'] = 20;
    // last watched pos. y
    $b['t_c'] = 'FFFFFF';
    // title color
    $b['t_s'] = 8;
    // title font size
    $b['t_x'] = 136;
    // title pos. x
    $b['t_y'] = 36;
    // title pos. y
    $b['o_c'] = 'AAAAAA';
    // title color
    $b['o_s'] = 8;
    // title font size
    $b['o_x'] = 136;
    // title pos. x
    $b['o_y'] = 51;
    // title pos. y
    $b['i_c'] = '808080';
    // info color
    $b['i_s'] = 6;
    // info font size
    $b['i_x'] = 130;
    // info pos. x
    $b['i_y'] = 63;
    // info pos. y
    $b['st_c'] = '000000';
    // stroke color
    $b['b_c'] = 'FFFFFF';
    // border color
    if ($data !== '0') {
        $banner_array = explode(';', $data);
        $banner = array();
        foreach ($banner_array as $val) {
            $i = explode(':', $val);
            $banner[$i[0]] = $i[1];
        }
        $b = $banner;
    }
    $bg_c = hex2rgb($b['bg_c']);
    $lw_c = hex2rgb($b['lw_c']);
    $t_c = hex2rgb($b['t_c']);
    $o_c = hex2rgb($b['o_c']);
    $i_c = hex2rgb($b['i_c']);
    $st_c = hex2rgb($b['st_c']);
    $b_c = hex2rgb($b['b_c']);
    $font = 'admin/css/font/archivonarrow.ttf';
    // background
    $banner = imagecreatetruecolor($b['w'], $b['h']);
    $bg_color = imagecolorallocate($banner, $bg_c['r'], $bg_c['g'], $bg_c['b']);
    imagefill($banner, 0, 0, $bg_color);
    // get poster and copy
    if (file_exists('cache/' . $table . '_' . $ban['id'] . '_f.jpg')) {
        $post = imagecreatefromjpeg('cache/' . $table . '_' . $ban['id'] . '_f.jpg');
    } elseif (file_exists('cache/' . $table . '_' . $ban['id'] . '.jpg')) {
        $post = imagecreatefromjpeg('cache/' . $table . '_' . $ban['id'] . '.jpg');
    } else {
        $post = imagecreatefromjpeg('templates/default/img/d_poster.jpg');
    }
    $width = imagesx($post);
    $height = imagesy($post);
    $new_height = $b['h'];
    $new_width = $width / ($height / $new_height);
    imagecopyresampled($banner, $post, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    // add gradient
    $width = $b['h'];
    $gradient = imagecreatetruecolor($width, $b['h']);
    $gradient_color = imagecolorallocatealpha($gradient, $bg_c['r'], $bg_c['g'], $bg_c['b'], 127);
    imagefill($gradient, 0, 0, $gradient_color);
    for ($x = 0; $x < $width; ++$x) {
        $alpha = 127 - $x * (127 / $width);
        $gradient_color = imagecolorallocatealpha($gradient, $bg_c['r'], $bg_c['g'], $bg_c['b'], $alpha);
        imageline($gradient, $x, 0, $x, $b['h'], $gradient_color);
    }
    imagecopyresampled($banner, $gradient, $new_width - $width, 0, 0, 0, $width, $b['h'], $width, $b['h']);
    // add text
    $last_watched_color = imagecolorallocate($banner, $lw_c['r'], $lw_c['g'], $lw_c['b']);
    $title_color = imagecolorallocate($banner, $t_c['r'], $t_c['g'], $t_c['b']);
    $o_title_color = imagecolorallocate($banner, $o_c['r'], $o_c['g'], $o_c['b']);
    $info_color = imagecolorallocate($banner, $i_c['r'], $i_c['g'], $i_c['b']);
    $stroke_color = imagecolorallocate($banner, $st_c['r'], $st_c['g'], $st_c['b']);
    imagettfstroketext($banner, $b['lw_s'], 0, $b['lw_x'], $b['lw_y'], $last_watched_color, $stroke_color, $font, $lang['i_last_played'], 1);
    imagettfstroketext($banner, $b['t_s'], 0, $b['t_x'], $b['t_y'], $title_color, $stroke_color, $font, (isset($ban['title']) ? $ban['title'] : '') . (isset($ban['season']) ? ' - ' . $ban['season'] . 'x' : '') . (isset($ban['episode']) ? $ban['episode'] . ' ' : '') . (isset($ban['e_title']) ? $ban['e_title'] : ''), 1);
    imagettfstroketext($banner, $b['o_s'], 0, $b['o_x'], $b['o_y'], $o_title_color, $stroke_color, $font, isset($ban['originaltitle']) ? $ban['originaltitle'] : '', 1);
    imagettfstroketext($banner, $b['i_s'], 0, $b['i_x'], $b['i_y'], $info_color, $stroke_color, $font, (isset($ban['year']) ? $ban['year'] : '') . ' | ' . (isset($ban['rating']) ? $ban['rating'] : '') . ' | ' . (isset($ban['runtime']) ? $ban['runtime'] . ' ' . $lang['i_minute'] : '') . ' | ' . (isset($ban['genre']) ? $ban['genre'] : '') . ' | ' . (isset($ban['country']) ? $ban['country'] : ''), 1);
    // icon
    $icon = imagecreatefrompng('admin/img/' . $table . '.png');
    imagecopy($banner, $icon, $b['w'] - 26, 6, 0, 0, 18, 18);
    // border
    $border_color = imagecolorallocate($banner, $b_c['r'], $b_c['g'], $b_c['b']);
    imageline($banner, 0, 0, $b['w'] - 1, 0, $border_color);
    imageline($banner, $b['w'] - 1, 0, $b['w'] - 1, $b['h'] - 1, $border_color);
    imageline($banner, 0, $b['h'] - 1, $b['w'] - 1, $b['h'] - 1, $border_color);
    imageline($banner, 0, 0, 0, $b['h'] - 1, $border_color);
    // save as file
    imagejpeg($banner, 'cache/' . $file, 100);
    return $b;
}