Beispiel #1
0
function create_image($user)
{
    global $fontname;
    global $quality;
    $file = "covers/" . md5($user[0]['name'] . $user[1]['name'] . $user[2]['name']) . ".jpg";
    // if the file already exists dont create it again just serve up the original
    //if (!file_exists($file)) {
    // define the base image that we lay our text on
    $im = imagecreatefromjpeg("pass.jpg");
    // setup the text colours
    $color['grey'] = imagecolorallocate($im, 54, 56, 60);
    $color['green'] = imagecolorallocate($im, 55, 189, 102);
    // this defines the starting height for the text block
    $y = imagesy($im) - $height - 365;
    // loop through the array and write the text
    foreach ($user as $value) {
        // center the text in our image - returns the x value
        $x = center_text($value['name'], $value['font-size']);
        imagettftext($im, $value['font-size'], 0, $x, $y + $i, $color[$value['color']], $fontname, $value['name']);
        // add 32px to the line height for the next text block
        $i = $i + 32;
    }
    // create the image
    imagejpeg($im, $file, $quality);
    //}
    return $file;
}
Beispiel #2
0
function create_image($user)
{
    global $quality;
    global $allsizearray;
    $files = "";
    $iteration = 0;
    foreach ($allsizearray as $banner => $size) {
        if ($iteration != 0) {
            $files .= "##";
        }
        $size = split('x', $size);
        $iwidth = $size[0];
        $iheight = $size[1];
        $bannersize = split('x', $banner);
        $files .= "covers/cpn_" . $bannersize[0] . "x" . $bannersize[1] . "_1&" . md5($user['standardwording'] . $iteration) . ".jpg";
        $file = "covers/cpn_" . $bannersize[0] . "x" . $bannersize[1] . "_1&" . md5($user['standardwording'] . $iteration) . ".jpg";
        // define the base image that we lay our text on
        if ($user['bgcolor2'] != "") {
            error_log("gradient creation");
            if ($user['angle'] == "horizontal") {
                $im = gradient($iwidth, $iheight, array($user['bgcolor'], $user['bgcolor2'], $user['bgcolor'], $user['bgcolor2']));
            } else {
                $im = gradient($iwidth, $iheight, array($user['bgcolor'], $user['bgcolor'], $user['bgcolor2'], $user['bgcolor2']));
            }
        } else {
            $im = imagecreate($iwidth, $iheight);
            $rgbbgcolor = hex2rgb($user['bgcolor']);
            $color['bgcolor'] = imagecolorallocate($im, $rgbbgcolor[0], $rgbbgcolor[1], $rgbbgcolor[2]);
        }
        // setup the text colours
        $rgbcolor = hex2rgb($user['color']);
        $color['color'] = imagecolorallocate($im, $rgbcolor[0], $rgbcolor[1], $rgbcolor[2]);
        // this defines the starting height for the text block
        $y = imagesy($im) - $iheight / 2 + 6;
        $wordingtext = "";
        $wordingtextvertical = "";
        if ($user['uppercase'] == true) {
            $wordingtext = strtoupper($user['standardwording']);
            $wordingtextvertical = strtoupper($user['verticalwording']);
        } elseif ($user['lowercase'] == true) {
            $wordingtext = strtolower($user['standardwording']);
            $wordingtextvertical = strtolower($user['verticalwording']);
        } else {
            $wordingtext = $user['standardwording'];
            $wordingtextvertical = $user['verticalwording'];
        }
        if ($iwidth / 3 > $iheight) {
            $words = explode(" ", $wordingtext);
        } else {
            if ($user['verticalwording'] != "") {
                $words = explode(" ", $wordingtextvertical);
            } else {
                $words = explode(" ", $wordingtext);
            }
        }
        if ($iwidth <= 200 && $iheight <= 200) {
            $fontsize = $user['font-size-small'];
            $lineheight = $user['line-height-small'];
        } elseif ($iwidth > 360 || $iheight >= 200) {
            $fontsize = $user['font-size-big'];
            $lineheight = $user['line-height-big'];
        } else {
            $fontsize = $user['font-size'];
            $lineheight = $user['line-height'];
        }
        $fontRegular = str_replace("-Bold", "-Regular", $user['font']);
        $fontRegular = str_replace("-CondBold", "-CondLight", $fontRegular);
        $fontRegular = str_replace("-Black", "-Regular", $fontRegular);
        $fontName = str_replace("-Regular", "", $fontRegular);
        $fontBold = str_replace("-Regular", "-Bold", $fontRegular);
        $fontItalic = str_replace("-Regular", "-Italic", $fontRegular);
        $fontBoldItalic = str_replace("-Regular", "-BoldItalic", $fontRegular);
        $wnum = count($words);
        $line = '';
        $text = '';
        $boldActive = false;
        $italicActive = false;
        $boldItalicActive = false;
        $dimensions = 0;
        for ($i = 0; $i < $wnum; $i++) {
            if ($words[$i] == "<br>" || $words[$i] == "<BR>") {
                $text .= $text != '' ? '##' . $words[$i] . ' ' : $words[$i] . ' ';
                $line = $words[$i] . ' ';
                continue;
            }
            $line .= $words[$i];
            if ($words[$i] == "**") {
                if ($boldActive != true) {
                    $boldActive = true;
                } else {
                    $boldActive = false;
                    $text .= $text != '' ? '** ##' . ' ' : ' ';
                    $line = '';
                    continue;
                }
            } elseif ($boldActive == true) {
                if (isset($fontstyleArray[$fontName])) {
                    $styles = explode(", ", $fontstyleArray[$fontName]);
                    foreach ($styles as $style) {
                        if ($style == "Bold") {
                            $dimensions = imagettfbbox($fontsize, 0, $fontBold, $line);
                        }
                    }
                }
            } else {
                $dimensions = imagettfbbox($fontsize, 0, $fontRegular, $line);
            }
            if ($words[$i] == "__") {
                if ($italicActive != true) {
                    $italicActive = true;
                } else {
                    $italicActive = false;
                    $text .= $text != '' ? '__ ##' . ' ' : ' ';
                    $line = '';
                    continue;
                }
            } elseif ($italicActive == true) {
                if (isset($fontstyleArray[$fontName])) {
                    $styles = explode(", ", $fontstyleArray[$fontName]);
                    foreach ($styles as $style) {
                        if ($style == "Italic") {
                            $dimensions = imagettfbbox($fontsize, 0, $fontItalic, $line);
                        }
                    }
                }
            } else {
                $dimensions = imagettfbbox($fontsize, 0, $fontRegular, $line);
            }
            if ($words[$i] == "//") {
                if ($boldItalicActive != true) {
                    $boldItalicActive = true;
                } else {
                    $boldItalicActive = false;
                    $text .= $text != '' ? '// ##' . ' ' : ' ';
                    $line = '';
                    continue;
                }
            } elseif ($boldItalicActive == true) {
                if (isset($fontstyleArray[$fontName])) {
                    $styles = explode(", ", $fontstyleArray[$fontName]);
                    foreach ($styles as $style) {
                        if ($style == "BoldItalic") {
                            $dimensions = imagettfbbox($fontsize, 0, $boldItalicActive, $line);
                        }
                    }
                }
            } else {
                $dimensions = imagettfbbox($fontsize, 0, $fontRegular, $line);
            }
            $lineWidth = $dimensions[2] - $dimensions[0];
            if ($lineWidth > $iwidth) {
                if ($boldActive == true) {
                    $text .= $text != '' ? '** ##' . $words[$i] . ' ' : $words[$i] . ' ';
                    $line = $words[$i] . ' ';
                } elseif ($italicActive == true) {
                    $text .= $text != '' ? '__ ##' . $words[$i] . ' ' : $words[$i] . ' ';
                    $line = $words[$i] . ' ';
                } elseif ($boldItalicActive == true) {
                    $text .= $text != '' ? '// ##' . $words[$i] . ' ' : $words[$i] . ' ';
                    $line = $words[$i] . ' ';
                } else {
                    $text .= $text != '' ? '##' . $words[$i] . ' ' : $words[$i] . ' ';
                    $line = $words[$i] . ' ';
                }
            } else {
                $text .= $words[$i] . ' ';
                $line .= ' ';
            }
        }
        $text = preg_replace("/(<br> *##)|(<br>##)|(## *<br>)|(##<br>)|(<BR> *##)|(<BR>##)|(## *<BR>)|(##<BR>)/", "##", $text);
        $pattern = "/(##)|(<\\s*br\\s*\\/?>)/";
        $wordings = preg_split($pattern, $text);
        $wordingIndex = 0;
        foreach ($wordings as $wording) {
            $wording = trim($wording);
            if (preg_match("/[a-zA-Z]/i", $wording)) {
                $wordingIndex++;
            } else {
                break;
            }
        }
        unset($wordings[$wordingIndex]);
        if (count($wordings) > 1) {
            $space = -(count($wordings) * $lineheight / 2) + $lineheight / 2;
        } else {
            $space = 0;
        }
        foreach ($wordings as $wording) {
            if (strpos($wording, '**') !== false) {
                $wording = str_replace("** ", "", $wording);
                $wording = str_replace(" ** ", "", $wording);
                $wording = str_replace(" **", "", $wording);
                $wording = str_replace("**", "", $wording);
                $wording = trim($wording);
                $x = center_text($wording, $fontsize, $iwidth, $fontBold);
                imagettftext($im, $fontsize, 0, $x, $y + $space, $color['color'], $fontBold, $wording);
            } elseif (strpos($wording, '__') !== false) {
                $wording = str_replace("__ ", "", $wording);
                $wording = str_replace(" __ ", "", $wording);
                $wording = str_replace(" __", "", $wording);
                $wording = str_replace("__", "", $wording);
                $wording = trim($wording);
                $x = center_text($wording, $fontsize, $iwidth, $fontItalic);
                imagettftext($im, $fontsize, 0, $x, $y + $space, $color['color'], $fontItalic, $wording);
            } elseif (strpos($wording, '//') !== false) {
                $wording = str_replace("// ", "", $wording);
                $wording = str_replace(" // ", "", $wording);
                $wording = str_replace(" //", "", $wording);
                $wording = str_replace("//", "", $wording);
                $wording = trim($wording);
                $x = center_text($wording, $fontsize, $iwidth, $fontBoldItalic);
                imagettftext($im, $fontsize, 0, $x, $y + $space, $color['color'], $fontBoldItalic, $wording);
            } else {
                $wording = trim($wording);
                $x = center_text($wording, $fontsize, $iwidth, $fontRegular);
                imagettftext($im, $fontsize, 0, $x, $y + $space, $color['color'], $fontRegular, $wording);
            }
            $space = $space + $lineheight;
        }
        // create the image
        imagejpeg($im, $file, $quality);
        $iteration++;
    }
    return $files;
}
Beispiel #3
0
function show_matrix($result, $fieldnames = array())
{
    $titles = array();
    $lengths = array();
    // this is for showing multidimensional arrays
    static $recursive_id = 1;
    foreach ($result as $row) {
        foreach ($row as $colname => $value) {
            if (!isset($titles[$colname])) {
                if (!isset($fieldnames[$colname])) {
                    $titles[$colname] = $colname;
                } else {
                    $titles[$colname] = $fieldnames[$colname];
                }
            }
            if (!is_array($value)) {
                if (!isset($lengths[$colname]) || $lengths[$colname] < strlen($value) + 2) {
                    $lengths[$colname] = max(strlen($value), strlen($titles[$colname]));
                    $lengths[$colname] += 2;
                }
            } else {
                $lengths[$colname] = strlen($titles[$colname]) + 2;
            }
        }
    }
    // show the titles
    foreach ($titles as $colname => $title) {
        $length = $lengths[$colname];
        echo "+" . str_repeat("-", $length);
    }
    echo "+\n";
    foreach ($titles as $colname => $title) {
        $length = $lengths[$colname];
        echo "|" . center_text($title, $length);
    }
    echo "|\n";
    foreach ($titles as $colname => $title) {
        $length = $lengths[$colname];
        echo "+" . str_repeat("-", $length);
    }
    echo "+\n";
    $recursive_items = array();
    // now show the values
    foreach ($result as $row) {
        foreach ($row as $colname => $value) {
            // recursively show the multi dimensional array
            if (is_array($value)) {
                if (array_key_exists($colname, $fieldnames)) {
                    $rec_titles = $fieldnames[$colname];
                } else {
                    $rec_titles = array();
                }
                $recursive_items[$recursive_id] = array("titles" => $rec_titles, "values" => $value);
                // show the reference # instead
                $value = "[" . $recursive_id . "]";
                $recursive_id++;
            }
            $length = $lengths[$colname];
            if (is_array($value)) {
                continue;
            }
            echo "| " . $value . str_repeat(" ", $length - strlen($value) - 1);
        }
        echo "|\n";
    }
    // show last line
    foreach ($titles as $colname => $title) {
        $length = $lengths[$colname];
        echo "+" . str_repeat("-", $length);
    }
    echo "+\n";
    // now recursively show the multidimensional array
    foreach ($recursive_items as $id => $item) {
        echo "\n";
        echo "[" . $id . "]:\n";
        show_output($item["values"], $item["titles"]);
    }
}