function ProcessImageName($imagename) { global $imagelist, $imagelistfull; global $imagecount; GetImagePaths($imagename, $fullpath, $thumbpath); $size = GlassyImageSize($fullpath, $imagename); if ($size[0] && $size[1] && ($size[2] == 99 || $size[2] < 4)) { $fileroot = explode('.', basename($imagename)); EnsureThumbnail($imagename, $size, THUMBSIZE); if (strcmp($fileroot[0], "null")) { $imagelist[$imagecount] = $imagename; $imagelistfull[$imagecount] = $thumbpath; $imagecount++; } } }
////// // Set Up Images // handle uploaded image, if any // make sure a user image directory exists @mkdir(USRIMGPATH, 0700); @chmod(USRIMGPATH, 0700); @mkdir(USRIMGTHUMBPATH, 0755); @chmod(USRIMGTHUMBPATH, 0755); if (!empty($_FILES[USERIMG]['tmp_name']) && $_FILES[USERIMG]['size'] < MAXUSRIMGSIZE) { $imagename = tempnam(USRIMGPATH, ""); move_uploaded_file($_FILES[USERIMG]['tmp_name'], $imagename); $_SESSION[USRIMGFILE] = $imagename; $_SESSION[USRIMGNAME] = $_FILES[USERIMG]['name']; $image_name = $_SESSION[USRIMGNAME]; // create a thumbnail $size = GlassyImageSize($imagename, $image_name); if ($size[0] && $size[1] && ($size[2] == 99 || $size[2] < 4)) { $fileroot = explode('.', basename($imagename)); EnsureThumbnail($image_name, $size, THUMBSIZE); } } // fix up strings that should be lower case $color = strtolower($color); $grcolor = strtolower($grcolor); $text_color = strtolower($text_color); $back_color = strtolower($back_color); $font_style = strtolower($font_style); $rcolor = strtolower($rcolor); $rgrcolor = strtolower($rgrcolor); $rtext_color = strtolower($rtext_color); $image_foregroundcolor = strtolower($image_foregroundcolor);
function MakeGradientFilledButtonPolygon($qualityfactor, $width_temp, $height_temp, &$actwoa, &$acthoa, $radius_temp, $color_inner, $color_outer, $text, $text_height_temp, $text_color = "black", $bkcolor = "white", $image_locate, $image_height_temp, $image_name, $image_foreground, $image_foregroundcolor, $image_transparent, $image_transparentcolor, $font_path = "") { $width = $qualityfactor * $width_temp; $height = $qualityfactor * $height_temp; $radius = $qualityfactor * $radius_temp; $text_height = $qualityfactor * $text_height_temp; $image_height = $qualityfactor * $image_height_temp; $fontname = $font_path; if ($fontname == "") { $fontname = FONT; } $baseimage = MakeFilledButtonPolygon($width, $height, $actwoa, $acthoa, $radius, $color_outer, $bkcolor); $ccolor_outer = new cColor($color_outer); $ccolor_inner = new cColor($color_inner); if ($radius > 0) { /* construct a gradient fill for this button */ for ($step = 0, $newr = $radius, $newh = $height, $neww = $width; $newr > 0; $step++, $newr--, $newh -= 2, $neww -= 2) { $newcolor = $ccolor_outer->GradientColor($ccolor_inner, 100 * sqrt(($radius - $newr) / $radius)); $overlayimage = MakeFilledButtonPolygon($neww, $newh, $actw, $acth, $newr, $newcolor->ColorHexVal()); imagecopymerge($baseimage, $overlayimage, $step, ($acthoa - $acth) / 1.5, 0, 0, $actw, $acth, 100); // imagecopymerge($baseimage, $overlayimage, $step, ($acthoa-$acth)/2, 0, 0, $actw, $acth, 100); ImageDestroy($overlayimage); } } $ctcolor = new cColor($text_color); $blk = $ctcolor->Allocate($baseimage); imagealphablending($baseimage, TRUE); // TEXT OVERLAY // find out the size of the text at that font size $txtlns = explode("\n", $text); $linecount = count($txtlns); $i = $linecount; foreach ($txtlns as $txtln) { $bbox = imagettfbbox($text_height, 0, $fontname, $txtln); $left_text = $bbox[0]; $right_text = $bbox[2]; $text_w = $right_text - $left_text; $text_x = $actwoa / 2.0 - $text_w / 2.0; if ($left_text < 0) { $text_x += abs($left_text); } // add factor for left overhang $text_y = $acthoa / 2 + $text_height / 2 * $linecount + $text_height / 6 * ($linecount - 1) - $text_height * ($i - 1) - $text_height / 3 * ($i - 1); $textlines[] = array('text' => $txtln, 'x' => $text_x, 'y' => $text_y, 'w' => $text_w); $widths[] = $text_w; $i--; } unset($txtln); $maxwidth = max($widths); // IMAGE OVERLAY $foreground_custom = strcmp($image_foreground, "custom") == 0; $foreground_auto = strcmp($image_foreground, "auto") == 0; $foreground_none = strcmp($image_foreground, "none") == 0; $transparent_custom = strcmp($image_transparent, "custom") == 0; $transparent_auto = strcmp($image_transparent, "auto") == 0; $transparent_none = strcmp($image_transparent, "none") == 0; $cicolor = new cColor("black"); if ($foreground_custom) { $cicolor = new cColor($image_foregroundcolor); } $citcolor = new cColor("white"); if ($transparent_custom) { $citcolor = new cColor($image_transparentcolor); } GetImagePaths($image_name, $img_path, $thumbpath); // $img_size = @getimagesize($img_path); $img_size = GlassyImageSize($img_path, $image_name); $img_overlay = "invalid"; switch ($img_size[2]) { case IMAGETYPE_GIF: $img_overlay = imagecreatefromgif($img_path); break; case IMAGETYPE_JPEG: $img_overlay = imagecreatefromjpeg($img_path); break; case IMAGETYPE_PNG: $img_overlay = imagecreatefrompng($img_path); break; case 99: // double-secret code for SVG $destfile = tempnam(IMGPATH, ""); @rename($destfile, $destfile . ".png"); $destfile = $destfile . ".png"; // we limit svg conversions to TWO colors only because there is no way to disable // antialiasing and antialiased images look like hell when we do color conversions // at a later step.. so, SVG images are relatively useless at this time $execarg = IMCONVERT . " -resize 10000" . "x{$image_height} -colors 2 {$img_path} {$destfile}"; @exec($execarg); $img_overlay = imagecreatefrompng($destfile); @unlink($destfile); $img_size[0] = imagesx($img_overlay); $img_size[1] = imagesy($img_overlay); break; default: break; } // image and text! $img_newh = 0; $img_neww = 0; $img_x = 0; $img_y = 0; if ($img_overlay !== "invalid") { $img_newh = $image_height; $img_neww = $img_newh * $img_size[0] / $img_size[1]; // palettize the user image if not already imagetruecolortopalette($img_overlay, FALSE, 256); // find the "foreground" color index, if configured to do so if (!$foreground_none) { $foregroundindex = imagecolorclosest($img_overlay, $cicolor->red, $cicolor->green, $cicolor->blue); // and set it to the text color if ($foregroundindex > -1) { imagecolorset($img_overlay, $foregroundindex, $ctcolor->red, $ctcolor->green, $ctcolor->blue); } } // find the transparent "background" color index, if configured to do so if (!$transparent_none) { $backgroundindex = imagecolorclosest($img_overlay, $citcolor->red, $citcolor->green, $citcolor->blue); if ($backgroundindex > -1) { imagecolortransparent($img_overlay, $backgroundindex); } } $img_y = $acthoa / 2 - $img_newh / 2; $img_x = $actwoa / 2 - $img_neww / 2; } // make adjustments for relative positions if (strcmp($image_locate, "left") == 0) { $img_x -= $maxwidth / 2 + 5; foreach ($textlines as &$textline) { $textline['x'] += $img_neww / 2; } unset($textline); } else { if (strcmp($image_locate, "right") == 0) { $img_x += $maxwidth / 2 + 5; foreach ($textlines as &$textline) { $textline['x'] -= $img_neww / 2; } unset($textline); } } if ($img_overlay !== "invalid" && strcmp($image_locate, "none") != 0) { imagecopyresampled($baseimage, $img_overlay, $img_x, $img_y, 0, 0, $img_neww, $img_newh, $img_size[0], $img_size[1]); } @imagedestroy($img_overlay); foreach ($textlines as $textline) { ImageTTFText($baseimage, $text_height, 0, $textline['x'], $textline['y'], $blk, $fontname, $textline['text']); } unset($textline); if ($radius > 0) { $radiusstart = floor($radius / 1.2); $radiuslimit = floor($radius / 2.2); $outersteps = $radiusstart - $radiuslimit; $blendfactor = 100; if ($outersteps) { $blendfactor = 100 * sqrt(1 / $outersteps); } // construct a hilight for this button // $chilitecolor = imagecolorresolvealpha ( $baseimage, 255, 255, 255, 80); for ($newr = $radiusstart; $newr >= $radiuslimit; $newr--) { $chilitecolor = imagecolorresolvealpha($baseimage, 255, 255, 255, 100 - floor(100 * ($newr - $radiuslimit) / ($radiusstart - $radiuslimit))); MyImageArc($baseimage, $radius - 1, $radius, 2 * $radiusstart, 2 * $newr, 180, 270, $chilitecolor); if ($actwoa > 2 * $radius) { ImageLine($baseimage, $radius, $radius - $newr, $actwoa - $radius - 1, $radius - $newr, $chilitecolor); } MyImageArc($baseimage, $actwoa - $radius, $radius, 2 * $radiusstart, 2 * $newr, 270, 0, $chilitecolor); } } $imagetemp = tempnam(IMGPATH, ""); ImagePNG($baseimage, $imagetemp); imagedestroy($baseimage); // experimental, fill the corners with transparent color if (strcmp(strtoupper($bkcolor), "CLEAR") == 0) { $execarg = IMMOGRIFY . " -transparent #454545 {$imagetemp}"; @exec($execarg); } if ($qualityfactor > 1) { $neww = $actwoa / $qualityfactor; $newh = $acthoa / $qualityfactor; $execarg = IMMOGRIFY . " -resize " . $neww . "x" . $newh . " {$imagetemp}"; @exec($execarg); } return $imagetemp; }