function pb_build_image($tag = 0) { global $pixelbee; // clear out the time limit set_time_limit(0); // verify some variables if (empty($_POST['text'])) { $_POST['text'] = "Your Text"; } // initialize settings $max_height = 0; $num_frames = 0; $overall_width = 0; $text = strtolower($_POST['text']); $font_file = $_SERVER['DOCUMENT_ROOT'] . "/glitter/fonts/" . $_POST['fontname'] . ".ttf"; $glitter_image = $_SERVER['DOCUMENT_ROOT'] . "/glitter/glitters/" . $_POST['glittername'] . ".gif"; // setup the proper text size switch ($_POST['textsize']) { // cases case (0): { $textsize = 20; break; } case (1): { $textsize = 30; break; } case (2): { $textsize = 40; break; } case (3): { $textsize = 50; break; } case (4): { $textsize = 60; break; } case (5): { $textsize = 70; break; } case (6): { $textsize = 80; break; } default: { $textsize = 50; break; } } // break down the pieces $pieces = explode("<", $text); $temp = implode("?*", $pieces); $pieces = explode(">", $temp); $temp = implode("*?", $pieces); $pieces = explode("?", $temp); // check if there are any empty pieces foreach ($pieces AS $pieceid => $piece) { // check if this piece is empty if (empty($pieces["$pieceid"])) { unset($pieces["$pieceid"]); } } // pre-process all of the text $ids = ''; $base_index = 0; $load_cache = array(); foreach ($pieces AS $index => $value) { // check for an image if (substr($value, 0, 3) == "*id") { // remove the *'s $value = str_replace("*", "", $value); // get the type $load_type = substr($value, 0, 2); // check for id type if ($load_type == "id") { // setup the full text $length = strlen($value); $id = substr($value, 2, $length - 2); // add this onto $ids $ids .= "," . intval($id); // insert this into the load cache $load_index = count($load_cache); $load_cache["$load_index"] = array($load_type => intval($id)); // increase $base_index $base_index++; } } else { // insert this into the load cache $load_index = count($load_cache); $load_cache["$base_index"]['letter'] = $value; } } // check if any ids were found $idcache = array(); if (!empty($ids)) { // grab these id's from the database if ($images = $pixelbee->db->query_read(" SELECT * FROM pb_image WHERE imageid IN (0" . $ids . ") ")) { // process the results while ($image = $pixelbee->db->fetch_array($images)) { // cache this image $imageid = $image['imageid']; $idcache["$imageid"] = $image; } } } // load the $glitter_base $glitter_base = new Imagick($glitter_image); $glitter_frames = $glitter_base->getNumberImages(); // pre-load all of the images $normal_height = 0; $image_cache = array(); foreach ($load_cache AS $load_index => $load_value) { // get the proper values foreach ($load_value AS $load_type => $value) { // should only need once break; } // check for the index $filepath = ''; switch ($load_type) { // id case ('id'): { // setup the proper image index $image_index = $load_type . "_" . $value; // finalize the filepath $image = $idcache["$value"]; $filepath = $_SERVER['DOCUMENT_ROOT'] . $image['foldername'] . "/" . $image['filename']; // check if this image is already loaded if (empty($image_cache["$image_index"])) { // check if the file was found if (file_exists($filepath)) { // get the imagick object $image_cache["$image_index"] = new Imagick($filepath); } } break; } // letter case ('letter'): { // setup the proper image index $image_index = $value; // create a new imagick object $image_cache["$image_index"] = new Imagick(); // process the entire number of glitter frames for ($i = 0; $i < $glitter_frames; $i++) { // create an imagickdraw object $draw = new ImagickDraw(); // start a new pattern called glitter $draw->pushPattern('glitter', 0, 0, 50, 50); // use the proper glitter base frame $glitter_base->setImageIndex($i); // composit the image on the pattern $draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $glitter_base); // close the pattern $draw->popPattern(); // use the pattern 'glitter' as the fill $draw->setFillPatternURL('#glitter'); // use the proper font type $draw->setFont($font_file); // set the font size $draw->setFontSize($textsize); // get the dimensions $dimension = $glitter_base->queryFontMetrics($draw, $value); // annoate the text $draw->annotation(0, $dimension['ascender'], $value); // add the image to the imagick object $image_cache["$image_index"]->newImage($dimension['textWidth'] + 5, $dimension['textHeight'] + 5, 'none'); $image_cache["$image_index"]->drawImage($draw); // destroy the drawing resource $draw->destroy(); } break; } } // get the proper width/height $frames = $image_cache["$image_index"]->getNumberImages(); $height = $image_cache["$image_index"]->getImageHeight(); $width = $image_cache["$image_index"]->getImageWidth(); // check for proper frames if ($frames > $num_frames) { // update the num frames $num_frames = $frames; } // check for max height if ($height > $max_height) { // update the max height $max_height = $height; } // increase the overall width $overall_width += $width; // check for letter if ($load_type == 'letter') { // check for proper normal height if ($normal_height < $height) { // update the normal height $normal_height = $height; } } } // check for tagging if ($tag) { // cache the tag $image_cache['tag'] = new Imagick($_SERVER['DOCUMENT_ROOT'] . "/glitter/site.gif"); } // create the initial canvas $canvas = new Imagick(); $canvas->setFormat("gif"); // process the number of frames for ($frames = 0; $frames < $num_frames; $frames++) { // init x-pos $x_pos = 0; // create the drawing resource $draw = new ImagickDraw(); // process all of the images $canvas_height = $max_height; $canvas_width = 0; foreach ($load_cache AS $load_index => $load_value) { // get the proper values foreach ($load_value AS $load_type => $value) { // should only need once break; } // check for a space if ($value == ' ') { // increase the x_pos $x_pos += PIXEL_SIZE_SPACE; // increase the canvas width too $canvas_width += PIXEL_SIZE_SPACE; // continue on continue; } // process the proper type switch ($load_type) { // id case ('id'): { // setup the proper image index $image_index = $load_type . "_" . $value; break; } // default default: { // setup the proper image index $image_index = $value; break; } } // verify the letter cache exists if (!empty($image_cache["$image_index"])) { // get the current width/height $image_cache["$image_index"]->setImageIndex($frames); $current_height = $image_cache["$image_index"]->getImageHeight(); $current_width = $image_cache["$image_index"]->getImageWidth(); // adjust the y-pos $y_pos = 0; if ($current_height < $canvas_height) { // calculate the proper y-pos $y_pos = ($canvas_height - $current_height) / 2; } // add on the letter $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache["$image_index"]); // increase the positions $x_pos += $current_width - PIXEL_SIZE_OVERLAP; $canvas_width += $current_width - PIXEL_SIZE_OVERLAP; } } // add on the last 2 pixels $canvas_width += PIXEL_SIZE_OVERLAP; // check for tagging if ($tag) { // get the current tag width/height $current_height = $image_cache['tag']->getImageHeight(); $current_width = $image_cache['tag']->getImageWidth(); // adjust the y-pos $y_pos = 0; if ($current_height < $canvas_height) { // calculate the proper y-pos $y_pos = intval($normal_height + (($canvas_height - $normal_height) / 2) - ($current_height * 1.5)); } // check for canvas size over 200 if ($canvas_width > 200) { // check if it's really big if ($canvas_width > 500) { // add on the tags $x_pos = 10; $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache['tag']); $x_pos = ($canvas_width / 2) - ($current_width / 2); $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache['tag']); $x_pos = $canvas_width - $current_width - 10; $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache['tag']); } else { // add on the tags $x_pos = 10; $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache['tag']); $x_pos = $canvas_width - $current_width - 10; $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache['tag']); } } else { // add on the tag $x_pos = ($canvas_width / 2) - ($current_width / 2); $draw->composite(Imagick::COMPOSITE_OVER, $x_pos, $y_pos, $current_width, $current_height, $image_cache['tag']); } } // add this onto the canvas $canvas->newImage($canvas_width, $canvas_height, 'none'); $canvas->drawImage($draw); // destroy the drawing resource $draw->destroy(); } // destroy all of the images foreach ($image_cache AS $image_index => $image) { // destroy the object $image_cache["$image_index"]->destroy(); } // return the canvas return $canvas; } // setup any templates needed $globaltemplates = array('glitter_maker_built', 'glitter_maker_content', 'glitter_maker_hosted'); // require the backend require_once('./global.php'); /*if ($_SERVER['REMOTE_ADDR'] != '99.178.251.29') { // display error echo "COMING SOON"; exit; }*/ // check if any 'do' was set if (empty($_REQUEST['do'])) { // force it to do main action $_REQUEST['do'] = 'main'; } // build the leftbar content foreach ($glitter_sections AS $section_title => $leftbar) { // setup the proper title $leftbar['title'] = $section_title; // process all sections $content = ''; foreach ($leftbar['sections'] AS $title => $url) { // fixup any settings $title = ":: " . $title; $link_style = $leftbar['link_style']; // build the proper content eval('$content .= "' . pixelbee_fetch_template('leftbar_listbits') . '";'); } // setup the proper content $leftbar['content'] = $content; // build the content eval('$globalvars[\'leftbar_HTML\'] .= "' . pixelbee_fetch_template('leftbar_list') . '";'); } // build the right bar html eval('$globalvars[\'rightbar_HTML\'] = "' . pixelbee_fetch_template('rightbar') . '";'); // add on the page header $page_nav = ''; $page_title = "Add Glitter Text"; eval('$globalvars[\'main_HTML\'] .= "' . pixelbee_fetch_template('page_content_header') . '";'); // check if it's grabbing an image if ($_POST['do'] == 'grabit') { // check if it's trashing it if (!empty($_POST['trashit'])) { // delete this file @unlink($_SERVER['DOCUMENT_ROOT'] . "/glitter/created/" . $_POST['file']); // now jump back to the main dolls page if (!empty($_POST['url']) && strstr($_POST['url'], "http://")) { // jump to the referer url header("Location: " . $_POST['url']); } else { // jump to the main dolls page header("Location: http://www.pixelbee.com/dolls/latest-p1.html"); } exit; } // get the image dimensions $imagesize = @getimagesize($_SERVER['DOCUMENT_ROOT'] . "/glitter/created/" . $_POST['file']); // upload this file to imageshack $xmlString = uploadToImageshack($_SERVER['DOCUMENT_ROOT'] . "/glitter/created/" . $_POST['file']); // begin parsing xml data if ($xmlString == 'failed') { // get the proper image size $canvaswidth = $imagesize['0']; $canvasheight = $imagesize['1']; // finalize any remaining settings $url = $pixelbee->url; list($outfile, $extension) = explode(".", $_POST['file']); // display the built image $globalvars['main_EXTRA'] = "class=\"main-content\""; $globalvars['main_HTML'] .= "