public function getAvatar($string, $widthHeight = 12, $theme = 'default') { $widthHeight = max($widthHeight, 12); $md5 = md5($string); $fileName = _TMP_DIR_ . '/' . $md5 . '.png'; if ($this->tmpFileExists($fileName)) { return $fileName; } // Create seed. $seed = intval(substr($md5, 0, 6), 16); mt_srand($seed); $body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1)); // Avatar random parts. $parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]); $avatar = imagecreate($widthHeight, $widthHeight); imagesavealpha($avatar, true); imagealphablending($avatar, false); $background = imagecolorallocate($avatar, 0, 0, 0); $line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55); imagecolortransparent($avatar, $background); imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background); // Fill avatar with random parts. foreach ($parts as &$part) { $this->drawPart($part, $avatar, $widthHeight, $line_colour, $background); } imagepng($avatar, $fileName); imagecolordeallocate($avatar, $line_colour); imagecolordeallocate($avatar, $background); imagedestroy($avatar); return $fileName; }
static function color(&$imgage, $color = 'ffffff', $delete = false) { $cd = str_split($color, strlen($color) > 4 ? 2 : 1); $color = imagecolorallocate($imgage, hexdec($cd[0]), hexdec($cd[1]), hexdec($cd[2])); $delete && imagecolordeallocate($imgage, $color); return $color; }
/** * Free resources used for this color */ function free() { if ($this->resource !== NULL) { @imagecolordeallocate($this->resource, $this->color); $this->resource = NULL; } }
/** * Renders the CAPTCHA image based on the code. * @param string the verification code * @return string image content */ protected function renderImage($code) { $image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor); imagecolordeallocate($image, $backColor); $foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100); if ($this->fontFile === null) { $this->fontFile = dirname(__FILE__) . '/Duality.ttf'; } $len = strlen($code); $fontSize = $this->height - $this->padding * 2; for ($i = 0; $i < $len; $i++) { $foreColor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); $angle = mt_rand(-20, 20); $x = 5 + $fontSize * $i; $y = 20; imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $code[$i]); imageline($image, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $foreColor); } imagecolordeallocate($image, $foreColor); header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); header("Content-type: image/png"); imagepng($image); imagedestroy($image); }
static function color($res, $color = 'ffffff', $del = false) { $cr = str_split($color, strlen($color) > 4 ? 2 : 1); $color = imagecolorallocate($res, hexdec($cr[0]), hexdec($cr[1]), hexdec($cr[2])); if ($del) { imagecolordeallocate($res, $color); } return $color; }
/** * render module icon. * * @param string $fpath base image file * @param string $dirname * @param string $trustDirname */ public static function render($fpath, $dirname, $trustDirname) { self::_prepare(); if (!file_exists($fpath)) { self::_error404(); } $im = @imagecreatefrompng($fpath); if ($im === false) { self::_error404(); } $mw = 79; // maximum width of drawing area $ox = 47; // offset X $oy = 12; // offset Y (if same directory name) $oy_d = 8; // offset Y for $dirname $oy_t = 19; // offset Y for $trustDirname $isSameDirname = $dirname == $trustDirname; imagealphablending($im, true); $color_d = imagecolorallocate($im, 0, 0, 0); $color_t = imagecolorallocate($im, 0xa0, 0xa0, 0xa0); // write dirname $cw = self::_getStringWidth($dirname); while ($cw > $mw) { // trim string if over length $dirname = substr($dirname, 0, -1); $cw = self::_getStringWidth($dirname); } $x = $ox + ($mw - $cw) / 2; $y = $isSameDirname ? $oy : $oy_d; self::_writeString($im, $x, $y, $dirname, $color_d); if (!$isSameDirname) { // write trust dirname if different $cw = self::_getStringWidth($trustDirname); while ($cw > $mw) { // trim string if over length $dirname = substr($trustDirname, 0, -1); $cw = self::_getStringWidth($dirname); } $x = $ox + ($mw - $cw) / 2; $y = $oy_t; self::_writeString($im, $x, $y, $trustDirname, $color_t); } self::_showImage($im); imagecolordeallocate($im, $color_d); imagecolordeallocate($im, $color_t); imagedestroy($im); self::_cleanup(); }
private function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct, $trans = NULL){ $dst_w = imagesx($dst_im); $dst_h = imagesy($dst_im); // bounds checking $src_x = max($src_x, 0); $src_y = max($src_y, 0); $dst_x = max($dst_x, 0); $dst_y = max($dst_y, 0); if ($dst_x + $src_w > $dst_w){ $src_w = $dst_w - $dst_x; } if ($dst_y + $src_h > $dst_h){ $src_h = $dst_h - $dst_y; } for($x_offset = 0; $x_offset < $src_w; $x_offset++){ for($y_offset = 0; $y_offset < $src_h; $y_offset++){ // get source & dest color $srccolor = imagecolorsforindex($src_im, imagecolorat($src_im, $src_x + $x_offset, $src_y + $y_offset)); $dstcolor = imagecolorsforindex($dst_im, imagecolorat($dst_im, $dst_x + $x_offset, $dst_y + $y_offset)); // apply transparency if (is_null($trans) || ($srccolor !== $trans)){ $src_a = $srccolor['alpha'] * $pct / 100; // blend $src_a = 127 - $src_a; $dst_a = 127 - $dstcolor['alpha']; $dst_r = ($srccolor['red'] * $src_a + $dstcolor['red'] * $dst_a * (127 - $src_a) / 127) / 127; $dst_g = ($srccolor['green'] * $src_a + $dstcolor['green'] * $dst_a * (127 - $src_a) / 127) / 127; $dst_b = ($srccolor['blue'] * $src_a + $dstcolor['blue'] * $dst_a * (127 - $src_a) / 127) / 127; $dst_a = 127 - ($src_a + $dst_a * (127 - $src_a) / 127); $color = imagecolorallocatealpha($dst_im, $dst_r, $dst_g, $dst_b, $dst_a); // paint if (!imagesetpixel($dst_im, $dst_x + $x_offset, $dst_y + $y_offset, $color)){ return false; } imagecolordeallocate($dst_im, $color); } } } return true; }
function showImage() { $image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor); imagecolordeallocate($image, $backColor); imagecolortransparent($image, $backColor); $text_color = imagecolorallocate($image, $this->text_color[0], $this->text_color[1], $this->text_color[2]); $fontFile = dirname(__FILE__) . '/fonts/Duality.ttf'; $length = strlen($this->code); $box = imagettfbbox(30, 0, $fontFile, $this->code); $w = $box[4] - $box[0] + $this->offset * ($length - 1); $h = $box[1] - $box[5]; $scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h); $x = 10; $y = round($this->height * 27 / 33); for ($i = 0; $i < $length; ++$i) { $fontSize = (int) (rand(26, 35) * $scale * 0.8); $angle = rand(-20, 30); $letter = $this->code[$i]; $o = rand(-2, 2); $box = imagettftext($image, $fontSize, $angle, $x, $y, $text_color, $fontFile, $letter); $x = $box[2] + $o; } if ($this->showLine) { $line_color = imagecolorallocate($image, $this->line_color[0], $this->line_color[1], $this->line_color[2]); for ($i = 0; $i < rand(4, 8); $i++) { imageline($image, 1, rand(1, 50), rand(150, 180), rand(1, 50), $line_color); } } header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); header("Content-type: image/png"); imagepng($image); imagedestroy($image); }
/** * Renders the CAPTCHA image based on the code using GD library. * @param string $code the verification code * @return string image contents in PNG format. */ protected function renderImageByGD($code) { $image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor); imagecolordeallocate($image, $backColor); if ($this->transparent) { imagecolortransparent($image, $backColor); } $foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100); $length = strlen($code); $box = imagettfbbox(30, 0, $this->fontFile, $code); $w = $box[4] - $box[0] + $this->offset * ($length - 1); $h = $box[1] - $box[5]; $scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h); $x = 10; $y = round($this->height * 27 / 40); for ($i = 0; $i < $length; ++$i) { $fontSize = (int) (rand(26, 32) * $scale * 0.8); $angle = rand(-10, 10); $letter = $code[$i]; $box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter); $x = $box[2] + $this->offset; } imagecolordeallocate($image, $foreColor); ob_start(); imagepng($image); imagedestroy($image); return ob_get_clean(); }
/** * muestra la imagen CAPTCHA basada en el codigo. * @param string el código de verificación * @return string contenido imagen */ protected function renderImage($code) { $image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor); imagecolordeallocate($image, $backColor); $foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100); if ($this->fontFile === null) { $this->fontFile = CAPTCHA_VENDOR_DIR . 'Duality.ttf'; } $offset = 2; $length = strlen($code); $box = imagettfbbox(30, 0, $this->fontFile, $code); $w = $box[4] - $box[0] - $offset * ($length - 1); $h = $box[1] - $box[5]; $scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h); $x = 10; $y = round($this->height * 27 / 40); for ($i = 0; $i < $length; ++$i) { $fontSize = (int) (rand(26, 32) * $scale * 0.8); $angle = rand(-10, 10); $letter = $code[$i]; $box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter); $x = $box[2] - $offset; } imagecolordeallocate($image, $foreColor); header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); header("Content-type: image/png"); imagepng($image); imagedestroy($image); }
if ($type == 'date') { $process[$country . '(' . $quantity . ' click)'] = $quantity; } else { $process[$country . '(' . round(intval($quantity) * 100 / $total, 2) . '%)'] = round(intval($quantity) * 100 / $total, 2); } } # google chart intergrated :| $imagechart = 'http://chart.apis.google.com/chart?chs=700x350&cht=p3&chco=7777CC|76A4FB|3399CC|3366CC|000000|7D5F5F|A94A4A|13E9E9|526767|DBD6D6&chd=t:'; $imagechart .= implode(',', array_values($process)); $imagechart .= '&chl='; $imagechart .= implode('|', array_keys($process)); $imagechart .= '&chtt=Banner Stats'; $imagechart = str_replace(' ', '%20', $imagechart); header("Content-type: image/png"); echo $geturl->get($imagechart); } else { $my_img = imagecreate(700, 80); $background = imagecolorallocate($my_img, 255, 255, 255); $text_colour = imagecolorallocate($my_img, 0, 0, 0); $line_colour = imagecolorallocate($my_img, 128, 255, 0); imagestring($my_img, 4, 30, 25, "no data", $text_colour); imagesetthickness($my_img, 5); imageline($my_img, 30, 45, 165, 45, $line_colour); header("Content-type: image/png"); imagepng($my_img); imagecolordeallocate($line_color); imagecolordeallocate($text_color); imagecolordeallocate($background); imagedestroy($my_img); } }
function Create($image, $text, $align, $font, $fontsize = 15, $resize_width = 0, $padding = 5, $text_color = -1, $shadow_color = -1) { $this->img = false; set_error_handler(array($this, "ErrorHandler")); // second, make sure its an image if (!(list($width, $height, $this->imgtype, $attr) = @getimagesize($image))) { return $this->ShowError("Error: Cannot get parameters of specified image"); } // ensure position is correct if (!in_array($align, array('tl', 'tr', 'bl', 'br'))) { $align = 'tl'; } // fix up the font size $fontsize = str_replace('px', '', trim($fontsize)); if ($fontsize == '' || !is_int($fontsize)) { $fontsize = 15; } // verify the font if (!($font = realpath($font))) { return $this->ShowError("Error: Invalid font specified!"); } switch ($this->imgtype) { case 1: // gif $this->img = @imagecreatefromgif($image); break; case 2: // jpg $this->img = @imagecreatefromjpeg($image); break; case 3: // png $this->img = @imagecreatefrompng($image); break; default: // i don't care about other formats return false; } if (!$this->img) { return $this->ShowError("Error: Cannot use specified image"); } // see if we need to resize the image first if ($resize_width != 0) { // todo: Add a 'max-width, max-height' parameter... $ratio = $width / $resize_width; $resize_height = intval($height / $ratio); $thumb_img = imagecreatetruecolor($resize_width, $resize_height); if (!imagecopyresampled($thumb_img, $this->img, 0, 0, 0, 0, $resize_width, $resize_height, $width, $height)) { return $this->ShowError("Error: Could not resize image!"); } // fix these $height = $resize_height; $width = $resize_width; // destroy original object imagedestroy($this->img); $this->img = $thumb_img; } // allocate colors for text if ($text_color === -1) { $text_color = imagecolorallocate($this->img, 255, 255, 255); } else { $text_color = imagecolorallocate($this->img, $text_color[0], $text_color[1], $text_color[2]); } // allocate colors for text shadow if ($shadow_color === -1) { $shadow_color = imagecolorallocate($this->img, 0, 0, 0); } else { $shadow_color = imagecolorallocate($this->img, $shadow_color[0], $shadow_color[1], $shadow_color[2]); } // next, we should try to create the text.. hopefully it wraps nicely putenv('GDFONTPATH=' . realpath('.')); // hack, just in case // grab the font height, M is supposed to be big, with any random chars lying around $font_height = $this->img_height(imagettfbbox($fontsize, 0, $font, 'Mjg')); $row_spacing = intval($font_height * 0.2); // purely arbitrary value $space_width = $this->img_width(imagettfbbox($fontsize, 0, $font, ' ')); // try and do our best imitation of wordwrapping $text_elements = explode(' ', str_replace("\n", '', str_replace("\r\n", '', $text))); // adjust this depending on alignment $top = $padding + $font_height; $left = $padding; // initialize $line_width = 0; $line_beginning = 0; // index of beginning of line $inc = 1; $c = count($text_elements); $i = 0; if ($align[0] == 'b') { $top = $height - $padding; $font_height = $font_height * -1; $row_spacing = $row_spacing * -1; $inc = -1; $i = $c - 1; } $dbg = get_get_var('dbg'); $line_beginning = $i; // draw text elements starting from alignment position.. for (; $i >= 0 && $i < $c; $i += $inc) { $lf_width = $this->img_width(imagettfbbox($fontsize, 0, $font, $text_elements[$i])); // add a space if ($i != $line_beginning) { $lf_width += $space_width; } // see if we've exceeded the max width if ($lf_width + $line_width + $padding * 2 > $width) { // draw it out then! if ($align[1] == 'r') { $left = $width - $padding - $line_width; } if ($align[0] == 'b') { $text = implode(' ', array_slice($text_elements, $i + 1, $line_beginning - $i)); } else { $text = implode(' ', array_slice($text_elements, $line_beginning, $i - $line_beginning)); } // draw the text imagettftext($this->img, $fontsize, 0, $left - 1, $top + 1, $shadow_color, $font, $text); imagettftext($this->img, $fontsize, 0, $left, $top, $text_color, $font, $text); // keep moving, reset params $top += $font_height + $row_spacing; $line_beginning = $i; $line_width = $lf_width; } else { // keep trucking $line_width += $lf_width; } } // get the last line too if ($line_width != 0) { if ($align[1] == 'r') { $left = $width - $padding - $line_width; } if ($align[0] == 'b') { $text = implode(' ', array_slice($text_elements, $i + 1, $line_beginning - $i)); } else { $text = implode(' ', array_slice($text_elements, $line_beginning, $i - $line_beginning)); } imagettftext($this->img, $fontsize, 0, $left - 1, $top + 1, $shadow_color, $font, $text); imagettftext($this->img, $fontsize, 0, $left, $top, $text_color, $font, $text); } imagecolordeallocate($this->img, $shadow_color); imagecolordeallocate($this->img, $text_color); restore_error_handler(); return true; }
function GenerateLegend() { global $sessionID, $mapName, $width, $height, $offsetX, $offsetY, $xPad, $yPad, $iconWidth, $iconHeight, $xIndent, $groupIcon, $fontIndex, $textColor; $userInfo = new MgUserInformation($sessionID); $siteConnection = new MgSiteConnection(); $siteConnection->Open($userInfo); $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); $mappingService = $siteConnection->CreateService(MgServiceType::MappingService); $map = new MgMap(); $map->Open($resourceService, $mapName); $scale = $map->GetViewScale(); CompileVisibleLayerCount($map); $image = imagecreatetruecolor($width, $height); $white = imagecolorallocate($image, 255, 255, 255); $textColor = imagecolorallocate($image, 0, 0, 0); imagefilledrectangle($image, 0, 0, $width, $height, $white); //Uncomment regions marked with BEGIN DEBUG / END DEBUG and comment out regions marked with //BEGIN COMMENT OUT IF DEBUGGING / END COMMENT OUT IF DEBUGGING to see what PHP-isms get spewed out //that may be tripping up rendering // //Also replace instances of "////print_r" with "//print_r" to insta-uncomment all debugging calls //==BEGIN DEBUG== //header("Content-type: text/html", true); //==END DEBUG== ProcessGroupsForLegend($mappingService, $resourceService, $map, $scale, NULL, $image); //==BEGIN COMMENT OUT IF DEBUGGING== header("Content-type: image/png"); imagepng($image); //==END COMMENT OUT IF DEBUGGING== //==BEGIN DEBUG== /* ob_start(); imagepng($image); $im = base64_encode(ob_get_contents()); ob_end_clean(); echo "<img src='data:image/png;base64,".$im."' alt='legend image'></img>"; */ //==END DEBUG== imagecolordeallocate($image, $white); imagecolordeallocate($image, $textColor); imagedestroy($image); }
function update_media($media) { parent::update_media($media); /** * Here we use a small hack; media height and width (in millimetres) match * the size of screenshot (in pixels), so we take them as-is */ $this->_heightPixels = $media->height(); $this->_widthPixels = $media->width(); $this->_image = imagecreatetruecolor($this->_widthPixels, $this->_heightPixels); /** * Render white background */ $white = imagecolorallocate($this->_image, 255, 255, 255); imagefill($this->_image, 0, 0, $white); imagecolordeallocate($this->_image, $white); $this->_color[0] = array('rgb' => array(0, 0, 0), 'object' => imagecolorallocate($this->_image, 0, 0, 0)); /** * Setup initial clipping region */ $this->_clipping = array(); $this->_saveClip(new Rectangle(new Point(0, 0), new Point($this->_widthPixels - 1, $this->_heightPixels - 1))); $this->_transform = new AffineTransform($this->_heightPixels, $this->_widthPixels / mm2pt($this->media->width()), $this->_heightPixels / mm2pt($this->media->height())); }
/** * Crops the image to the biggest fitting, centered square * */ function CenterSquarify(ArgbColor $backgroundColor = null) { $width = $this->Width(); $height = $this->Height(); $squareSize = min($width, $height); $xOrigin = 0; $yOrigin = 0; if ($width > $squareSize) { $xOrigin = round(($width - $squareSize) / 2); } else { if ($height > $squareSize) { $yOrigin = round(($height - $squareSize) / 2); } } $destRes = \imagecreatetruecolor($squareSize, $squareSize); if ($backgroundColor) { $colRes = \imagecolorallocate($destRes, $backgroundColor->GetRed(), $backgroundColor->GetGreen(), $backgroundColor->GetBlue()); \imagefill($destRes, 0, 0, $colRes); \imagecolordeallocate($destRes, $colRes); } \imagecopy($destRes, $this->resource, 0, 0, $xOrigin, $yOrigin, $squareSize, $squareSize); $this->AssignResource($destRes); }
function complexImg() { if (isset(FileGen::$cliOpts['help'])) { echo "\n"; echo "available options for subScript 'complexImg':\n"; // modeMask echo "--talentbgs (backgrounds for talent calculator)\n"; // 0x01 echo "--maps (generates worldmaps)\n"; // 0x02 echo "--spawn-maps (creates alphaMasks of each zone to check spawns against)\n"; // 0x04 echo "--artwork (optional: imagery from /glues/credits (not used, skipped by default))\n"; // 0x08 echo "--area-maps (optional: renders maps with highlighted subZones for each area)\n"; // 0x10 return true; } $mapWidth = 1002; $mapHeight = 668; $threshold = 95; // alpha threshold to define subZones: set it too low and you have unspawnable areas inside a zone; set it too high and the border regions overlap $runTime = ini_get('max_execution_time'); $locStr = null; $dbcPath = CLISetup::$srcDir . '%sDBFilesClient/'; $imgPath = CLISetup::$srcDir . '%sInterface/'; $destDir = 'static/images/wow/'; $success = true; $paths = ['WorldMap/', 'TalentFrame/', 'Glues/Credits/']; $modeMask = 0x7; // talentBGs, regular maps, spawn-related alphaMaps $createAlphaImage = function ($w, $h) { $img = imagecreatetruecolor($w, $h); imagesavealpha($img, true); imagealphablending($img, false); $bgColor = imagecolorallocatealpha($img, 0, 0, 0, 127); imagefilledrectangle($img, 0, 0, imagesx($img) - 1, imagesy($img) - 1, $bgColor); imagecolortransparent($img, $bgColor); imagealphablending($img, true); imagecolordeallocate($img, $bgColor); return $img; }; // prefer manually converted PNG files (as the imagecreatefromblp-script has issues with some formats) // alpha channel issues observed with locale deDE Hilsbrad and Elwynn - maps // see: https://github.com/Kanma/BLPConverter $loadImageFile = function ($path) { $result = null; $file = $path . '.png'; if (CLISetup::fileExists($file)) { CLISetup::log('manually converted png file present for ' . $path . '.', CLISetup::LOG_WARN); $result = imagecreatefrompng($file); } if (!$result) { $file = $path . '.blp'; if (CLISetup::fileExists($file)) { $result = imagecreatefromblp($file); } } return $result; }; $assembleImage = function ($baseName, $order, $w, $h) use($loadImageFile) { $dest = imagecreatetruecolor($w, $h); imagesavealpha($dest, true); imagealphablending($dest, false); $_h = $h; foreach ($order as $y => $row) { $_w = $w; foreach ($row as $x => $suffix) { $src = $loadImageFile($baseName . $suffix); if (!$src) { CLISetup::log(' - complexImg: tile ' . $baseName . $suffix . '.blp missing.', CLISetup::LOG_ERROR); unset($dest); return null; } imagecopyresampled($dest, $src, 256 * $x, 256 * $y, 0, 0, min($_w, 256), min($_h, 256), min($_w, 256), min($_h, 256)); $_w -= 256; unset($src); } $_h -= 256; } return $dest; }; $writeImage = function ($name, $ext, $src, $w, $h, $done) { $ok = false; $dest = imagecreatetruecolor($w, $h); imagesavealpha($dest, true); imagealphablending($dest, false); imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, imagesx($src), imagesy($src)); switch ($ext) { case 'jpg': $ok = imagejpeg($dest, $name . '.' . $ext, 85); break; case 'png': $ok = imagepng($dest, $name . '.' . $ext); break; default: CLISetup::log($done . ' - unsupported file fromat: ' . $ext, CLISetup::LOG_WARN); } imagedestroy($dest); if ($ok) { chmod($name . '.' . $ext, CLISetup::FILE_ACCESS); CLISetup::log($done . ' - image ' . $name . '.' . $ext . ' written', CLISetup::LOG_OK); } else { CLISetup::log($done . ' - could not create image ' . $name . '.' . $ext, CLISetup::LOG_ERROR); } return $ok; }; $createSpawnMap = function ($img, $zoneId) use($mapHeight, $mapWidth, $threshold) { CLISetup::log(' - creating spawn map'); $tmp = imagecreate(1000, 1000); $cbg = imagecolorallocate($tmp, 255, 255, 255); $cfg = imagecolorallocate($tmp, 0, 0, 0); for ($y = 0; $y < 1000; $y++) { for ($x = 0; $x < 1000; $x++) { $a = imagecolorat($img, $x * $mapWidth / 1000, $y * $mapHeight / 1000) >> 24; imagesetpixel($tmp, $x, $y, $a < $threshold ? $cfg : $cbg); } } imagepng($tmp, 'setup/generated/alphaMaps/' . $zoneId . '.png'); imagecolordeallocate($tmp, $cbg); imagecolordeallocate($tmp, $cfg); imagedestroy($tmp); }; $checkSourceDirs = function ($sub, &$missing = []) use($imgPath, $dbcPath, $paths, &$modeMask) { $hasMissing = false; foreach ($paths as $idx => $subDir) { if ($idx == 0 && !($modeMask & 0x16)) { // map related continue; } else { if ($idx == 1 && !($modeMask & 0x1)) { // talentBGs continue; } else { if ($idx == 2 && !($modeMask & 0x8)) { // artwork continue; } } } $p = sprintf($imgPath, $sub) . $subDir; if (!CLISetup::fileExists($p)) { $hasMissing = true; $missing[] = $p; } } if ($modeMask & 0x17) { $p = sprintf($dbcPath, $sub); if (!CLISetup::fileExists($p)) { $hasMissing = true; $missing[] = $p; } } return !$hasMissing; }; // do not change order of params! if ($_ = FileGen::hasOpt('talentbgs', 'maps', 'spawn-maps', 'artwork', 'area-maps')) { $modeMask = $_; } foreach (CLISetup::$expectedPaths as $xp => $__) { if ($xp) { // if in subDir add trailing slash $xp .= '/'; } if ($checkSourceDirs($xp, $missing)) { $locStr = $xp; break; } } // if no subdir had sufficient data, diaf if ($locStr === null) { CLISetup::log('one or more required directories are missing:', CLISetup::LOG_ERROR); foreach ($missing as $m) { CLISetup::log(' - ' . $m, CLISetup::LOG_ERROR); } return; } /**************/ /* TalentTabs */ /**************/ if ($modeMask & 0x1) { if (CLISetup::writeDir($destDir . 'hunterpettalents/') && CLISetup::writeDir($destDir . 'talents/backgrounds/')) { // [classMask, creatureFamilyMask, tabNr, textureStr] $tTabs = DB::Aowow()->select('SELECT tt.creatureFamilyMask, tt.textureFile, tt.tabNumber, cc.fileString FROM dbc_talenttab tt LEFT JOIN dbc_chrclasses cc ON cc.Id = (LOG(2, tt.classMask) + 1)'); $order = array(['-TopLeft', '-TopRight'], ['-BottomLeft', '-BottomRight']); if ($tTabs) { $sum = 0; $total = count($tTabs); CLISetup::log('Processing ' . $total . ' files from TalentFrame/ ...'); foreach ($tTabs as $tt) { ini_set('max_execution_time', 30); // max 30sec per image (loading takes the most time) $sum++; $done = ' - ' . str_pad($sum . '/' . $total, 8) . str_pad('(' . number_format($sum * 100 / $total, 2) . '%)', 9); if ($tt['creatureFamilyMask']) { $size = [244, 364]; $name = $destDir . 'hunterpettalents/bg_' . (log($tt['creatureFamilyMask'], 2) + 1); } else { $size = [204, 554]; $name = $destDir . 'talents/backgrounds/' . strtolower($tt['fileString']) . '_' . ($tt['tabNumber'] + 1); } if (!isset(FileGen::$cliOpts['force']) && file_exists($name . '.jpg')) { CLISetup::log($done . ' - file ' . $name . '.jpg was already processed'); continue; } $im = $assembleImage(sprintf($imgPath, $locStr) . 'TalentFrame/' . $tt['textureFile'], $order, 256 + 44, 256 + 75); if (!$im) { CLISetup::log(' - could not assemble file ' . $tt['textureFile'], CLISetup::LOG_ERROR); continue; } if (!$writeImage($name, 'jpg', $im, $size[0], $size[1], $done)) { $success = false; } } } else { $success = false; } ini_set('max_execution_time', $runTime); } else { $success = false; } } /************/ /* Worldmap */ /************/ if ($modeMask & 0x16) { $mapDirs = array(['maps/%snormal/', 'jpg', 488, 325], ['maps/%soriginal/', 'jpg', 0, 0], ['maps/%ssmall/', 'jpg', 224, 163], ['maps/%szoom/', 'jpg', 772, 515]); // as the js expects them $baseLevelFix = array(4264 => 1, 4265 => 1, 4415 => 1, 4416 => 1, 4493 => 0, 4500 => 1, 4603 => 1, 4723 => 1, 4809 => 1, 4813 => 1, 4820 => 1, 717 => 1, 3713 => 1, 2437 => 1, 3716 => 1, 3847 => 1, 718 => 1, 3717 => 1, 3714 => 1, 3562 => 1, 722 => 1, 491 => 1, 3792 => 1, 3789 => 1, 1477 => 1, 3959 => 0, 3845 => 1, 2717 => 1, 3923 => 1, 3607 => 1, 3836 => 1, 2159 => 1, 4075 => 0); $wmo = DB::Aowow()->select('SELECT *, worldMapAreaId AS ARRAY_KEY, Id AS ARRAY_KEY2 FROM dbc_worldmapoverlay WHERE textureString <> ""'); $wma = DB::Aowow()->select('SELECT * FROM dbc_worldmaparea'); if (!$wma || !$wmo) { $success = false; CLISetup::log(' - could not read required dbc files: WorldMapArea.dbc [' . count($wma) . ' entries]; WorldMapOverlay.dbc [' . count($wmo) . ' entries]', CLISetup::LOG_ERROR); return; } // fixups... foreach ($wma as &$a) { if ($a['areaId']) { continue; } switch ($a['Id']) { case 13: $a['areaId'] = -6; break; // Kalimdor // Kalimdor case 14: $a['areaId'] = -3; break; // Eastern Kingdoms // Eastern Kingdoms case 466: $a['areaId'] = -2; break; // Outland // Outland case 485: $a['areaId'] = -5; break; // Northrend } } array_unshift($wma, ['Id' => -1, 'areaId' => -1, 'nameINT' => 'World'], ['Id' => -4, 'areaId' => -4, 'nameINT' => 'Cosmic']); $sumMaps = count(CLISetup::$localeIds) * count($wma); CLISetup::log('Processing ' . $sumMaps . ' files from WorldMap/ ...'); foreach (CLISetup::$localeIds as $progressLoc => $l) { // create destination directories $dirError = false; foreach ($mapDirs as $md) { if (!CLISetup::writeDir($destDir . sprintf($md[0], strtolower(Util::$localeStrings[$l]) . '/'))) { $dirError = true; } } if ($modeMask & 0x4) { if (!CLISetup::writeDir('setup/generated/alphaMaps')) { $dirError = true; } } if ($dirError) { $success = false; CLISetup::log(' - complexImg: could not create map directories for locale ' . $l . '. skipping...', CLISetup::LOG_ERROR); continue; } // source for mapFiles $mapSrcDir = null; $locDirs = array_filter(CLISetup::$expectedPaths, function ($var) use($l) { return !$var || $var == $l; }); foreach ($locDirs as $mapLoc => $__) { if ($mapLoc) { // and trailing slash again $mapLoc .= '/'; } $p = sprintf($imgPath, $mapLoc) . $paths[0]; if (CLISetup::fileExists($p)) { CLISetup::log(' - using files from ' . ($mapLoc ?: '/') . ' for locale ' . Util::$localeStrings[$l], CLISetup::LOG_WARN); $mapSrcDir = $p . '/'; break; } } if ($mapSrcDir === null) { $success = false; CLISetup::log(' - no suitable localized map files found for locale ' . $l, CLISetup::LOG_ERROR); continue; } foreach ($wma as $progressArea => $areaEntry) { $curMap = $progressArea + count($wma) * $progressLoc; $progress = ' - ' . str_pad($curMap . '/' . $sumMaps, 10) . str_pad('(' . number_format($curMap * 100 / $sumMaps, 2) . '%)', 9); $wmaId = $areaEntry['Id']; $zoneId = $areaEntry['areaId']; $textureStr = $areaEntry['nameINT']; $path = $mapSrcDir . $textureStr; if (!CLISetup::fileExists($path)) { $success = false; CLISetup::log('worldmap file ' . $path . ' missing for selected locale ' . Util::$localeStrings[$l], CLISetup::LOG_ERROR); continue; } $fmt = array([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]); CLISetup::log($textureStr . " [" . $zoneId . "]"); $overlay = $createAlphaImage($mapWidth, $mapHeight); // zone has overlays (is in open world; is not multiLeveled) if (isset($wmo[$wmaId])) { CLISetup::log(' - area has ' . count($wmo[$wmaId]) . ' overlays'); foreach ($wmo[$wmaId] as &$row) { $i = 1; $y = 0; while ($y < $row['h']) { $x = 0; while ($x < $row['w']) { $img = $loadImageFile($path . '/' . $row['textureString'] . $i); if (!$img) { CLISetup::log(' - complexImg: tile ' . $path . '/' . $row['textureString'] . $i . '.blp missing.', CLISetup::LOG_ERROR); break 2; } imagecopy($overlay, $img, $row['x'] + $x, $row['y'] + $y, 0, 0, imagesx($img), imagesy($img)); // prepare subzone image if ($modeMask & 0x10) { if (!isset($row['maskimage'])) { $row['maskimage'] = $createAlphaImage($row['w'], $row['h']); $row['maskcolor'] = imagecolorallocatealpha($row['maskimage'], 255, 64, 192, 64); } for ($my = 0; $my < imagesy($img); $my++) { for ($mx = 0; $mx < imagesx($img); $mx++) { if (imagecolorat($img, $mx, $my) >> 24 < $threshold) { imagesetpixel($row['maskimage'], $x + $mx, $y + $my, $row['maskcolor']); } } } } imagedestroy($img); $x += 256; $i++; } $y += 256; } } // create spawn-maps if wanted if ($modeMask & 0x4) { $createSpawnMap($overlay, $zoneId); } } // check, if the current zone is multiLeveled // if there are also files present without layer-suffix assume them as layer: 0 $multiLeveled = false; $multiLevel = 0; do { if (!CLISetup::filesInPath('/' . $textureStr . '\\/' . $textureStr . ($multiLevel + 1) . '_\\d\\.blp/i', true)) { break; } $multiLevel++; $multiLeveled = true; } while ($multiLevel < 18); // Karazhan has 17 frickin floors // check if we can create base map anyway $file = $path . '/' . $textureStr . '1.blp'; $hasBaseMap = CLISetup::fileExists($file); CLISetup::log(' - area has ' . ($multiLeveled ? $multiLevel . ' levels' : 'only base level')); $map = null; for ($i = 0; $i <= $multiLevel; $i++) { ini_set('max_execution_time', 120); // max 120sec per image $file = $path . '/' . $textureStr; if (!$i && !$hasBaseMap) { continue; } // if $multiLeveled also suffix -0 to baseMap if it exists if ($i && $multiLeveled) { $file .= $i . '_'; } $doSkip = 0x0; $outFile = []; foreach ($mapDirs as $idx => $info) { $outFile[$idx] = $destDir . sprintf($info[0], strtolower(Util::$localeStrings[$l]) . '/') . $zoneId; $floor = $i; if ($zoneId == 4100) { // ToCStratholme: map order fix $floor += 1; } if ($multiLeveled && !(isset($baseLevelFix[$zoneId]) && $i == $baseLevelFix[$zoneId])) { $outFile[$idx] .= '-' . $floor; } if (!isset(FileGen::$cliOpts['force']) && file_exists($outFile[$idx] . '.' . $info[1])) { CLISetup::log($progress . ' - file ' . $outFile[$idx] . '.' . $info[1] . ' was already processed'); $doSkip |= 1 << $idx; } } if ($doSkip == 0xf) { continue; } $map = $assembleImage($file, $fmt, $mapWidth, $mapHeight); if (!$map) { $success = false; CLISetup::log(' - could not create image resource for map ' . $zoneId . ($multiLevel ? ' level ' . $i : '')); continue; } if (!$multiLeveled) { imagecopymerge($map, $overlay, 0, 0, 0, 0, imagesx($overlay), imagesy($overlay), 100); imagedestroy($overlay); } // create map if ($modeMask & 0x2) { foreach ($mapDirs as $idx => $info) { if ($doSkip & 1 << $idx) { continue; } if (!$writeImage($outFile[$idx], $info[1], $map, $info[2] ?: $mapWidth, $info[3] ?: $mapHeight, $progress)) { $success = false; } } } } // also create subzone-maps if ($map && isset($wmo[$wmaId]) && $modeMask & 0x10) { foreach ($wmo[$wmaId] as &$row) { $doSkip = 0x0; $outFile = []; foreach ($mapDirs as $idx => $info) { $outFile[$idx] = $destDir . sprintf($info[0], strtolower(Util::$localeStrings[$l]) . '/') . $row['areaTableId']; if (!isset(FileGen::$cliOpts['force']) && file_exists($outFile[$idx] . '.' . $info[1])) { CLISetup::log($progress . ' - file ' . $outFile[$idx] . '.' . $info[1] . ' was already processed'); $doSkip |= 1 << $idx; } } if ($doSkip == 0xf) { continue; } $subZone = imagecreatetruecolor($mapWidth, $mapHeight); imagecopy($subZone, $map, 0, 0, 0, 0, imagesx($map), imagesy($map)); imagecopy($subZone, $row['maskimage'], $row['x'], $row['y'], 0, 0, imagesx($row['maskimage']), imagesy($row['maskimage'])); foreach ($mapDirs as $idx => $info) { if ($doSkip & 1 << $idx) { continue; } if (!$writeImage($outFile[$idx], $info[1], $subZone, $info[2] ?: $mapWidth, $info[3] ?: $mapHeight, $progress)) { $success = false; } } imagedestroy($subZone); } } if ($map) { imagedestroy($map); } } } } /***********/ /* Credits */ /***********/ if ($modeMask & 0x8) { if (CLISetup::writeDir($destDir . 'Interface/Glues/Credits/')) { // tile ordering $order = array(1 => array([1]), 2 => array([1], [2]), 4 => array([1, 2], [3, 4]), 6 => array([1, 2, 3], [4, 5, 6]), 8 => array([1, 2, 3, 4], [5, 6, 7, 8])); $imgGroups = []; $srcPath = sprintf($imgPath, $locStr) . 'Glues/Credits/'; $files = CLISetup::filesInPath($srcPath); foreach ($files as $f) { if (preg_match('/([^\\/]+)(\\d).blp/i', $f, $m)) { if ($m[1] && $m[2]) { if (!isset($imgGroups[$m[1]])) { $imgGroups[$m[1]] = $m[2]; } else { if ($imgGroups[$m[1]] < $m[2]) { $imgGroups[$m[1]] = $m[2]; } } } } } // errör-korrekt $imgGroups['Desolace'] = 4; $imgGroups['BloodElf_Female'] = 6; $total = count($imgGroups); $sum = 0; CLISetup::log('Processing ' . $total . ' files from Glues/Credits/...'); foreach ($imgGroups as $file => $fmt) { ini_set('max_execution_time', 30); // max 30sec per image (loading takes the most time) $sum++; $done = ' - ' . str_pad($sum . '/' . $total, 8) . str_pad('(' . number_format($sum * 100 / $total, 2) . '%)', 9); $name = $destDir . 'Interface/Glues/Credits/' . $file; if (!isset(FileGen::$cliOpts['force']) && file_exists($name . '.png')) { CLISetup::log($done . ' - file ' . $name . '.png was already processed'); continue; } if (!isset($order[$fmt])) { CLISetup::log(' - pattern for file ' . $name . ' not set. skipping', CLISetup::LOG_WARN); continue; } $im = $assembleImage($srcPath . $file, $order[$fmt], count($order[$fmt][0]) * 256, count($order[$fmt]) * 256); if (!$im) { CLISetup::log(' - could not assemble file ' . $name, CLISetup::LOG_ERROR); continue; } if (!$writeImage($name, 'png', $im, count($order[$fmt][0]) * 256, count($order[$fmt]) * 256, $done)) { $success = false; } } ini_set('max_execution_time', $runTime); } else { $success = false; } } return $success; }
protected function renderImage($code) { if ($this->mode == self::MODE_MATH_ADVANCED) { $code = $this->showCode($code); } $image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor); imagecolordeallocate($image, $backColor); if ($this->transparent) { imagecolortransparent($image, $backColor); } $foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100); if ($this->fontFile === null) { $this->fontFile = dirname(__FILE__) . '/fonts/Duality.ttf'; } $length = strlen($code); $box = imagettfbbox(30, 0, $this->fontFile, $code); $w = $box[4] - $box[0] + $this->offset * ($length - 1); $h = $box[1] - $box[5]; $scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h); $x = 10; $y = round($this->height * 27 / 40); if ($this->useAdvanced) { // random font color $r = (int) ($this->foreColor % 0x1000000 / 0x10000); $g = (int) ($this->foreColor % 0x10000 / 0x100); $b = $this->foreColor % 0x100; $foreColor = imagecolorallocate($image, mt_rand($r - 50, $r + 50), mt_rand($g - 50, $g + 50), mt_rand($b - 50, $b + 50)); } for ($i = 0; $i < $length; ++$i) { $fontSize = (int) (rand(26, 32) * $scale * 0.8); $angle = rand(-10, 10); $letter = $code[$i]; if ($this->useAdvanced) { // random font color if (mt_rand(0, 10) > 7) { $foreColor = imagecolorallocate($image, mt_rand($r - 50, $r + 50), mt_rand($g - 50, $g + 50), mt_rand($b - 50, $b + 50)); } } $box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter); $x = $box[2] + $this->offset; } if ($this->useAdvanced) { // add density dots $this->density = (int) $this->density; if ($this->density > 0) { $length = intval($this->width * $this->height / 100 * $this->density); $c = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); for ($i = 0; $i < $length; ++$i) { $x = mt_rand(0, $this->width); $y = mt_rand(0, $this->height); imagesetpixel($image, $x, $y, $c); } } // add lines $this->lines = (int) $this->lines; if ($this->lines > 0) { for ($i = 0; $i < $this->lines; ++$i) { imagesetthickness($image, mt_rand(1, 2)); // gray lines only to save human eyes:-) $c = imagecolorallocate($image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); $x = mt_rand(0, $this->width); $y = mt_rand(0, $this->width); imageline($image, $x, 0, $y, $this->height, $c); } } // filled flood section $this->fillSections = (int) $this->fillSections; if ($this->fillSections > 0) { for ($i = 0; $i < $this->fillSections; ++$i) { $c = imagecolorallocate($image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); $x = mt_rand(0, $this->width); $y = mt_rand(0, $this->width); imagefill($image, $x, $y, $c); } } } imagecolordeallocate($image, $foreColor); if (ob_get_contents()) { ob_clean(); } header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); header("Content-type: image/png"); imagepng($image); imagedestroy($image); }
/** * Generate Radar Chart * * @return @e void */ protected function _drawRadar() { //----------------------------------------- // Draw Legend & Axes //----------------------------------------- foreach ($this->data['yaxis'] as $key => $series) { $this->legend[$key] = $series['name']; } if (!$this->_drawLegend()) { return false; } //----------------------------------------- // Figure out center position //----------------------------------------- $xmid = $this->grapharea['x0'] + round(($this->grapharea['x1'] - $this->grapharea['x0']) / 2, 0); $ymid = $this->grapharea['y0'] + round(($this->grapharea['y1'] - $this->grapharea['y0']) / 2, 0); //----------------------------------------- // Figure out size //----------------------------------------- $maxlabelwidth = 0; $maxlabelheight = 0; foreach ($this->data['xaxis'] as $label) { if ($this->use_ttf) { $textsize = imagettfbbox(10, 0, $this->options['font'], $label); if ($textsize[2] - $textsize[0] > $maxlabelwidth) { $maxlabelwidth = $textsize[2] - $textsize[0]; } if ($textsize[1] - $textsize[5] > $maxlabelheight) { $maxlabelheight = $textsize[1] - $textsize[5]; } } else { $textsize = imagefontwidth($this->fontsize) * strlen($label); if ($textsize > $maxlabelwidth) { $maxlabelwidth = $textsize; } $maxlabelheight = imagefontheight($this->fontsize); } } $lengthx = floor(($this->grapharea['x1'] - $this->grapharea['x0']) / 2 - 5 - $maxlabelwidth); $lengthy = floor(($this->grapharea['y1'] - $this->grapharea['y0']) / 2 - 5 - $maxlabelheight); $armlength = $lengthx > $lengthy ? $lengthy : $lengthx; $numaxes = count($this->data['yaxis'][0]['data']); $maxvalue = $this->_getMax($this->data['yaxis']); $numticks = $this->options['numticks'] > $maxvalue ? floor($maxvalue) : $this->options['numticks']; $maxvalue = ceil($maxvalue / $numticks) * $numticks; //----------------------------------------- // Allocate text and shadow cols //----------------------------------------- $textcolor = imagecolorallocate($this->image, hexdec(substr($this->options['titlecolor'], 1, 2)), hexdec(substr($this->options['titlecolor'], 3, 2)), hexdec(substr($this->options['titlecolor'], 5, 2))); $shadowcolor = imagecolorallocate($this->image, hexdec(substr($this->options['titleshadow'], 1, 2)), hexdec(substr($this->options['titleshadow'], 3, 2)), hexdec(substr($this->options['titleshadow'], 5, 2))); //----------------------------------------- // A spider draws a web //----------------------------------------- $webxy = array(); $webtick = array(); $textxy = array(); for ($i = 0; $i < $numaxes; $i++) { $rotation = -90 + round($i * 360 / $numaxes, 0); // Web axes $webxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * $armlength; $webxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * $armlength; imageline($this->image, $xmid, $ymid, $webxy[$i * 2], $webxy[$i * 2 + 1], $this->black); // Calculate web tick for ($j = 0; $j < $this->options['numticks']; $j++) { $webtickxy[$j][$i * 2] = $xmid + cos(deg2rad($rotation)) * (($j + 1) * $armlength / $this->options['numticks']); $webtickxy[$j][$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * (($j + 1) * $armlength / $this->options['numticks']); } // Calculate the label positions $label = $this->data['xaxis'][$i]; if ($this->use_ttf) { $textsize = imagettfbbox(10, 0, $this->options['font'], $label); $textwidth = $textsize[4] - $textsize[0]; $textheight = $textsize[1] - $textsize[5]; } else { $textwidth = imagefontwidth($this->fontsize) * strlen($label); $textheight = imagefontheight($this->fontsize); } if ($rotation > -90 && $rotation < 90) { $textxy[] = $webxy[$i * 2] + 5; $textxy[] = $webxy[$i * 2 + 1] + floor($textheight / 2); } elseif ($rotation == -90) { $textxy[] = $webxy[$i * 2] - floor($textwidth / 2); $textxy[] = $webxy[$i * 2 + 1] - 5; } elseif ($rotation == 90) { $textxy[] = $webxy[$i * 2] - floor($textwidth / 2); $textxy[] = $webxy[$i * 2 + 1] + 5 + $textheight; } else { $textxy[] = $webxy[$i * 2] - 5 - $textwidth; $textxy[] = $webxy[$i * 2 + 1] + floor($textheight / 2); } // Draw the labels if ($this->use_ttf) { imagettftext($this->image, "10", 0, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1, $shadowcolor, $this->options['font'], $label); imagettftext($this->image, "10", 0, $textxy[$i * 2], $textxy[$i * 2 + 1], $textcolor, $this->options['font'], $label); } else { imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1 - imagefontheight($this->fontsize), $label, $shadowcolor); imagestring($this->image, $this->fontsize, $textxy[$i * 2], $textxy[$i * 2 + 1] - imagefontheight($this->fontsize), $label, $textcolor); } } //----------------------------------------- // Draw the web lines //----------------------------------------- foreach ($webtickxy as $tickxy) { imagepolygon($this->image, $tickxy, $numaxes, $this->black); } //----------------------------------------- // Draw the axes value text //----------------------------------------- $numticks = $this->options['numticks'] > $maxvalue ? floor($maxvalue) : $this->options['numticks']; $tick = $maxvalue / $numticks; for ($j = 0; $j < $this->options['numticks']; $j++) { $value = ($j + 1) * $tick; if ($this->use_ttf) { $textsize = imagettfbbox(10, 0, $this->options['font'], $value); $textheight = $textsize[1] - $textsize[5]; imagettftext($this->image, "10", 0, $webtickxy[$j][0] + 6, $webtickxy[$j][1] + floor($textheight / 2) + 1, $shadowcolor, $this->options['font'], $value); imagettftext($this->image, "10", 0, $webtickxy[$j][0] + 5, $webtickxy[$j][1] + floor($textheight / 2), $textcolor, $this->options['font'], $value); } else { imagestring($this->image, $this->fontsize, $webtickxy[$j][0] + 6, $webtickxy[$j][1] - floor(imagefontheight($this->fontsize) / 2) + 1, $value, $shadowcolor); imagestring($this->image, $this->fontsize, $webtickxy[$j][0] + 5, $webtickxy[$j][1] - floor(imagefontheight($this->fontsize) / 2), $value, $textcolor); } } //----------------------------------------- // Draw the series //----------------------------------------- $numseries = count($this->data['yaxis']); for ($ci = 0; $ci < $numseries; $ci++) { if (!isset($this->color[$ci])) { $this->color[$ci] = explode(",", $this->_getSliceColor($this->data['yaxis'][$ci]['color'])); } $linecolor = ImageColorAllocate($this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2]); $dotcolor = imagecolorallocate($this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2]); $dotshadowcolor = imagecolorallocate($this->image, $this->color[$ci][0] - 50 < 0 ? 0 : $this->color[$ci][0] - 50, $this->color[$ci][1] - 50 < 0 ? 0 : $this->color[$ci][1] - 50, $this->color[$ci][2] - 50 < 0 ? 0 : $this->color[$ci][2] - 50); //----------------------------------------- // Get the x and y's for the lines //----------------------------------------- $linesxy = array(); $lineshadowxy = array(); $textxy = array(); for ($i = 0; $i < $numaxes; $i++) { $value = $this->data['yaxis'][$ci]['data'][$i]; $rotation = -90 + round($i * 360 / $numaxes, 0); $linesxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * floor($value / $maxvalue * $armlength); $linesxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * floor($value / $maxvalue * $armlength); $lineshadowxy[$i * 2] = $linesxy[$i * 2] + 1; $lineshadowxy[$i * 2 + 1] = $linesxy[$i * 2 + 1] + 1; if ($this->options['showdatalabels']) { // Calculate the datalabel positions $textxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * floor($value / $maxvalue * $armlength + 5); $textxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * floor($value / $maxvalue * $armlength + 5); if ($this->use_ttf) { $textsize = imagettfbbox(10, 0, $this->options['font'], $value); $textwidth = $textsize[4] - $textsize[0]; $textheight = $textsize[1] - $textsize[5]; } else { $textwidth = imagefontwidth($this->fontsize) * strlen($value); $textheight = imagefontheight($this->fontsize); } if ($rotation > -90 && $rotation < 90) { $textxy[$i * 2] = $textxy[$i * 2] + 5; $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + floor($textheight / 2); } elseif ($rotation == -90) { $textxy[$i * 2] = $textxy[$i * 2] - floor($textwidth / 2); $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] - 5; } elseif ($rotation == 90) { $textxy[$i * 2] = $textxy[$i * 2] - floor($textwidth / 2); $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + 5 + $textheight; } else { $textxy[$i * 2] = $textxy[$i * 2] - 5 - $textwidth; $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + floor($textheight / 2); } } } //----------------------------------------- // Draw the lines, dots and text //----------------------------------------- imagepolygon($this->image, $linesxy, $numaxes, $linecolor); imagepolygon($this->image, $lineshadowxy, $numaxes, $dotshadowcolor); $valuecolor = ImageColorAllocate($this->image, hexdec(substr($this->options['textcolor'], 1, 2)), hexdec(substr($this->options['textcolor'], 3, 2)), hexdec(substr($this->options['textcolor'], 5, 2))); $valshadecolor = imagecolorallocate($this->image, $this->color[$ci][0] - 50 < 0 ? 0 : $this->color[$ci][0] - 50, $this->color[$ci][1] - 50 < 0 ? 0 : $this->color[$ci][1] - 50, $this->color[$ci][2] - 50 < 0 ? 0 : $this->color[$ci][2] - 50); for ($i = 0; $i < $numaxes; $i++) { imagefilledellipse($this->image, $linesxy[$i * 2] + 1, $linesxy[$i * 2 + 1] + 1, 7, 7, $dotshadowcolor); imagefilledellipse($this->image, $linesxy[$i * 2], $linesxy[$i * 2 + 1], 7, 7, $dotcolor); if ($this->options['showdatalabels']) { $value = $this->data['yaxis'][$ci]['data'][$i]; if ($this->use_ttf) { imagettftext($this->image, "10", 0, $textxy[$i * 2] - 1, $textxy[$i * 2 + 1] - 1, $valshadecolor, $this->options['font'], $value); imagettftext($this->image, "10", 0, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1, $valshadecolor, $this->options['font'], $value); imagettftext($this->image, "10", 0, $textxy[$i * 2] + 2, $textxy[$i * 2 + 1] + 2, $valshadecolor, $this->options['font'], $value); imagettftext($this->image, "10", 0, $textxy[$i * 2], $textxy[$i * 2 + 1], $valuecolor, $this->options['font'], $value); } else { imagestring($this->image, $this->fontsize, $textxy[$i * 2] - 1, $textxy[$i * 2 + 1] - 1 - imagefontheight($this->fontsize), $label, $valshadecolor); imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1 - imagefontheight($this->fontsize), $label, $valshadecolor); imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 2, $textxy[$i * 2 + 1] + 2 - imagefontheight($this->fontsize), $label, $valshadecolor); imagestring($this->image, $this->fontsize, $textxy[$i * 2], $textxy[$i * 2 + 1] - imagefontheight($this->fontsize), $label, $valuecolor); } } } imagecolordeallocate($this->image, $linecolor); imagecolordeallocate($this->image, $dotcolor); imagecolordeallocate($this->image, $dotshadowcolor); imagecolordeallocate($this->image, $valshadecolor); imagecolordeallocate($this->image, $valuecolor); } return true; }
<?php $image = imagecreatetruecolor(180, 30); $white = imagecolorallocate($image, 255, 255, 255); $result = imagecolordeallocate('image', $white);
public function resizeImage() { $rNewImage = imagecreatetruecolor($this->iWidth, $this->iHeight); // retrieve version number since version_compare can't handle versions like “bundled (2.1.0 compatible)” // prerelease versions are not processed anymore $sVersion = preg_replace("/.*?((\\d+\\.){1,2}\\d+).*/", '$1', self::$GD_INFO['GD Version']); if ($this->sFileType === 'png' && version_compare($sVersion, '2.0.1', '>=')) { $rTransparent = imagecolorallocatealpha($rNewImage, 0, 0, 0, 127); imagefill($rNewImage, 0, 0, $rTransparent); imagecolordeallocate($rNewImage, $rTransparent); imagealphablending($rNewImage, true); } imagecopyresampled($rNewImage, $this->rImageHandle, 0, 0, 0, 0, $this->iWidth, $this->iHeight, $this->iOriginalWidth, $this->iOriginalHeight); imagedestroy($this->rImageHandle); $this->rImageHandle = $rNewImage; $this->iOriginalHeight = $this->iHeight; $this->iOriginalWidth = $this->iWidth; }
/** Generate CAPTCHA image @param $_dimx integer @param $_dimy integer @param $_len integer @param $_ttfs string @public **/ public static function captcha($_dimx, $_dimy, $_len, $_ttfs = 'cube') { $_base = self::rgb(F3::$global['BGCOLOR']); $_trans = F3::$global['FGTRANS']; // Specify Captcha seed if (!strlen(session_id())) { session_start(); } $_SESSION['captcha'] = substr(md5(uniqid()), 0, $_len); F3::$global['SESSION'] =& $_SESSION; // Font size $_size = min($_dimx / $_len, 0.6 * $_dimy); // Load TrueType font file $_fonts = explode('|', $_ttfs); $_file = F3::$global['FONTS'] . F3::fixSlashes($_fonts[mt_rand(0, count($_fonts) - 1)]) . '.ttf'; F3::$global['PROFILE']['FILES']['fonts'][basename($_file)] = filesize($_file); $_maxdeg = 15; // Compute bounding box metrics $_bbox = imagettfbbox($_size, $_angle, $_file, $_SESSION['captcha']); $_wimage = 0.9 * (max($_bbox[2], $_bbox[4]) - max($_bbox[0], $_bbox[6])); $_himage = max($_bbox[1], $_bbox[3]) - max($_bbox[5], $_bbox[7]); // Create blank image $_captcha = imagecreatetruecolor($_dimx, $_dimy); list($_r, $_g, $_b) = $_base; $_bg = imagecolorallocate($_captcha, $_r, $_g, $_b); imagefill($_captcha, 0, 0, $_bg); $_width = 0; // Insert each Captcha character for ($_i = 0; $_i < $_len; $_i++) { // Random angle $_angle = $_maxdeg - mt_rand(0, $_maxdeg * 2); // Get CAPTCHA character from session cookie $_char = $_SESSION['captcha'][$_i]; $_fg = imagecolorallocatealpha($_captcha, mt_rand(0, 255 - $_trans), mt_rand(0, 255 - $_trans), mt_rand(0, 255 - $_trans), $_trans); imagettftext($_captcha, $_size, $_angle, ($_dimx - $_wimage) / 2 + $_i * $_wimage / $_len, ($_dimy - $_himage) / 2 + 0.9 * $_himage, $_fg, $_file, $_char); imagecolordeallocate($_captcha, $_fg); } // Make the background transparent imagecolortransparent($_captcha, $_bg); // Send output as PNG image if (PHP_SAPI != 'cli' && !headers_sent()) { header(F3::HTTP_Content . ': image/png'); } imagepng($_captcha, NULL, self::PNG_Compress, PNG_NO_FILTER); // Free resources imagedestroy($_captcha); }
function set_image_label_subtitle_color($red = 0, $green = 0, $blue = 0) { if (is_int($this->image_label_subtitle_color)) { imagecolordeallocate($this->image, $this->image_label_subtitle_color); } $this->image_label_subtitle_color = imagecolorallocate($this->image, $red, $green, $blue); $this->image_label_subtitle_color_rgb = array($red, $green, $blue); }
<?php $image = imagecreatetruecolor(180, 30); $white = imagecolorallocate($image, 255, 255, 255); $resource = tmpfile(); $result = imagecolordeallocate($resource, $white);
/** * @param resource $image * * @return bool */ public function Deallocate($image) { return imagecolordeallocate($image, $this->_resource); }
$rgb['shadow'] = rgb_merge(rgb_complementary($rgb['foreground']), rgb_create(255, 255, 255)); } $color = array(); foreach ($rgb as $name => $value) { $color[$name] = imagecolorallocate($im, $value['r'], $value['g'], $value['b']); } imagefilledrectangle($im, 0, 0, $im_wdth, $im_hght, $color['background']); for ($i = 0; $i < rand(5, 9); $i++) { $x = rand(0, $im_wdth); $y = rand(0, $im_hght); $f = rand(0, 5); $c = rgb_grayscale(rgb_rand(127 - $strt, 254 - $strt)); $color[$i] = imagecolorallocate($im, $c['r'], $c['g'], $c['b']); imagestring($im, $f, $x, $y, $cdata['captcha_string'], $color[$i]); } $x = rand($im_wdth - floor($im_wdth / 2), $im_wdth + floor($im_wdth / 2)) - imagefontwidth(7) * strlen($cdata['captcha_string']) >> 1; $y = rand($im_hght - floor($im_hght / 2), $im_hght + floor($im_hght / 2)) - imagefontheight(7) >> 1; imagestring($im, 7, $x + 1, $y + 1, $cdata['captcha_string'], $color['shadow']); imagestring($im, 7, $x - 1, $y - 1, $cdata['captcha_string'], $color['shadow']); imagestring($im, 7, $x + 1, $y - 1, $cdata['captcha_string'], $color['shadow']); imagestring($im, 7, $x - 1, $y + 1, $cdata['captcha_string'], $color['shadow']); imagestring($im, 7, $x, $y, $cdata['captcha_string'], $color['foreground']); header('Content-type: image/png'); imagepng($im); foreach ($color as $name => $value) { imagecolordeallocate($im, $value); } imagedestroy($im); } exit; }
/** * Destroy this image and all allocated resources. Do not invoke any * instance methods after this function has been called. */ public function destroy() { foreach ($this->__allocated_colors as $color) { imagecolordeallocate($this->__img, $color); } $this->__allocated_colors = array(); imagedestroy($this->__img); }
function addScribble($image, $width, $height) { for ($i = 0; $i < 8; $i++) { $color = imagecolorallocate($image, rand(100, 180), rand(100, 180), rand(100, 180)); $points = array(); for ($j = 1; $j < rand(5, 10); $j++) { $points[] = rand(2 * (20 * ($i + 1)), 2 * (50 * ($i + 1))); $points[] = rand(30, $height + 30); } imagesetthickness($image, rand(2, 6)); imagepolygon($image, $points, intval(sizeof($points) / 2), $color); imagecolordeallocate($image, $color); } }
/** * 生成验证码图像,返回 QView_Output 对象 * * $param string $code * * @return QView_Output */ function generateImage($code) { // 确定要使用的字体 if (isset(self::$_font_list[$this->_options['font']])) { $font = Q_DIR . '/_resources/' . self::$_font_list[$this->_options['font']]; } else { $font = $this->_options['font']; } // 确定图像的宽度和高度 $border = $this->_options['border']; $float_pixel = intval($this->_options['float_pixel']); $padding = intval($this->_options['padding']); $width = intval($this->_options['width']) + $padding * 2 + $border * 2 + 1; $width *= 2; $height = intval($this->_options['height']) + $padding * 2 + $border * 2 + 1 + $float_pixel; // 创建图像 $img = imagecreatetruecolor($width, $height); // 绘制背景 list($r, $g, $b) = Helper_ImgCode::hex2rgb($this->_options['bgcolor']); imagefilledrectangle($img, $border, $border, $width - $border - 1, $height - $border - 1, imagecolorallocate($img, $r, $g, $b)); // 绘制文字 $max_angle = intval($this->_options['max_angle']); $x = $padding + $padding + $border; $bottom = $height - $padding + $border - $float_pixel * 2; $font_space = $this->_options['font_space']; $color_arr = Helper_ImgCode::hex2rgb($this->_options['color']); $arr = array(); $font_size = $this->_options['font_size']; $min_r = $r + 50; $min_g = $g + 50; $min_b = $b + 50; for ($i = 0, $max = strlen($code); $i < $max; $i++) { $arr[$i]['font_size'] = mt_rand(50, 150) / 100 * $font_size; $arr[$i]['angle'] = rand(0, $max_angle) - $max_angle / 2; list($r, $g, $b) = $color_arr; $r = ($r + rand(0, 2550)) % (255 - $min_r) + $min_r; $g = ($g + rand(0, 2550)) % (255 - $min_g) + $min_g; $b = ($b + rand(0, 2550)) % (255 - $min_b) + $min_b; $arr[$i]['color'] = imagecolorallocate($img, $r, $g, $b); } for ($i = 0; $i < $max; $i++) { $x += $font_space; $y = $bottom; list(, , $x) = imagettftext($img, $arr[$i]['font_size'], $arr[$i]['angle'], $x, $y, $arr[$i]['color'], $font, $code[$i]); imagecolordeallocate($img, $arr[$i]['color']); } $new_width = intval($this->_options['width']) + $padding * 2 + $border * 2 + 1; $img_output = imagecreatetruecolor($new_width, $height); imagecopyresampled($img_output, $img, 0, 0, 0, 0, $new_width, $height, $x + $padding + $border, $height); imagedestroy($img); // 绘制边框 if ($border) { list($r, $g, $b) = Helper_ImgCode::hex2rgb($this->_options['bdcolor']); imagerectangle($img_output, 0, 0, $width, $height, imagecolorallocate($img_output, $r, $g, $b)); } $filename = 'imgcode-' . mt_rand(); ob_start(); // 输出图像 switch (strtolower($this->_options['image_type'])) { case 'png': $filename .= '.png'; $mime = image_type_to_mime_type(IMAGETYPE_PNG); imagepng($img_output); break; case 'gif': $filename .= '.gif'; $mime = image_type_to_mime_type(IMAGETYPE_GIF); imagegif($img_output); break; case 'jpg': default: $filename .= '.jpg'; $mime = image_type_to_mime_type(IMAGETYPE_JPEG); imagejpeg($img_output); } imagedestroy($img_output); $output = new QView_Output($filename, $mime, ob_get_clean()); $output->enableClientCache(false); return $output; }
/** * \brief Clear the generated colors. * * \param $image An image resource. */ public function clearColors($image) { foreach ($this->colors as $index => $color) { imagecolordeallocate($image, $color['resource']); $this->colors[$index]['resource'] = null; } }
public function render($params = array()) { $roit1 = rand(1, 6); $font = dirname(__FILE__) . DS . 'catcha_fonts' . DS . 'font' . $roit1 . '.ttf'; $font = normalize_path($font, 0); if (function_exists('imagettftext')) { $text1 = mt_rand(100, 4500); } else { $text1 = mt_rand(100, 999); } $text2 = mt_rand(2, 9); $roit = mt_rand(1, 5); $text = "{$text1}"; $answ = $text1; $x = 100; $y = 20; $image = @imagecreate($x, 20) or die('Unable to render a CAPTCHA picture!'); $tcol1z = rand(1, 150); $ttcol1z1 = rand(0, 150); $tcol1z11 = rand(0, 150); $bgcolor = imagecolorallocate($image, 255, 255, 255); $gray = imagecolorallocate($image, 240, 240, 240); // $black = imagecolorallocate($image, $tcol1z, $ttcol1z1, $tcol1z11); $black = imagecolorallocate($image, 0, 0, 0); $captcha_sid = 'captcha'; if (isset($params['id'])) { $captcha_sid = 'captcha_' . $params['id']; } elseif (isset($_GET['id'])) { $captcha_sid = 'captcha_' . $_GET['id']; } $old = mw()->user_manager->session_get('captcha'); if ($old != false) { $old_array = mw()->user_manager->session_get('captcha_recent'); if (!is_array($old_array)) { $old_array = array(); } array_unshift($old_array, $old); array_slice($old_array, 20); mw()->user_manager->session_set('captcha_recent', $old_array); } $sess = mw()->user_manager->session_set($captcha_sid, $answ); $col1z = rand(200, 242); $col1z1 = rand(150, 242); $col1z11 = rand(150, 242); $color1 = imagecolorallocate($image, $col1z, $col1z1, $tcol1z11); $color2 = imagecolorallocate($image, $tcol1z - 1, $ttcol1z1 - 1, $tcol1z11 - 2); // imagefill($image, 0, 0, $color1); for ($i = 0; $i < $x; ++$i) { for ($j = 0; $j < $y; ++$j) { if (mt_rand(0, 20) < 10) { //$coords = array(mt_rand(0, 10), mt_rand(0, 10), mt_rand(0, 10), mt_rand(0, 10), 5, 6); $y21 = mt_rand(5, 20); $this->captcha_vector($image, $x - mt_rand(0, 10), mt_rand(0, 10), mt_rand(0, 180), 200, $bgcolor); // imagesetpixel($image, $i, $j, $color2); } } } $x1 = mt_rand(0, 5); $y1 = mt_rand(20, 22); $tsize = rand(13, 15); $pad = 2; // extra char spacing for text if (function_exists('imagettftext')) { imagettftext($image, $tsize, $roit, $x1, $y1, $black, $font, $text); } else { if (function_exists('imagestring')) { $font = mw_includes_path() . DS . 'admin' . DS . 'catcha_fonts' . DS . 'font' . $roit1 . '.gdf'; $font = normalize_path($font, 0); $font = imageloadfont($font); imagestring($image, $font, 0, 0, $text, $black); } else { } } $s = 180; $e = 360; if (function_exists('imagefilter')) { $filter_img = rand(1, 6); switch ($filter_img) { case 1: $gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0)); imageconvolution($image, $gaussian, 16, 0); break; // break; // break; case 3: imagefilter($image, IMG_FILTER_PIXELATE, 1); break; default: break; } } $y21 = mt_rand(5, 20); $this->captcha_vector($image, $x, $y21 / 2, 180, 200, $bgcolor); $y21 = mt_rand(5, 20); $this->captcha_vector($image, $x, $y21 / 2, $col1z11, 200, $bgcolor); $y21 = mt_rand(5, 20); $this->captcha_vector($image, $x / 3, $y21 / 3, $col1z11, 200, $bgcolor); if (function_exists('imagestring')) { $this->captcha_vector($image, $x / 3, $y21 / 3, $col1z11, 200, $gray); imagestring($image, 0, $y21, 2, $text, $gray); } // $emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1)); // $embize = mt_rand(1, 4); header('Content-type: image/png'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); imagepng($image); imagecolordeallocate($image, $bgcolor); imagecolordeallocate($image, $black); imagedestroy($image); }