function drawRating($rating) { $width = 300; $height = 15; $ratingbar = $rating / 100 * $width - 2; $image = imagecreate($width, $height); $fill = ImageColorAllocate($image, 67, 219, 0); if ($rating > 74) { $fill = ImageColorAllocate($image, 233, 233, 0); } if ($rating > 89) { $fill = ImageColorAllocate($image, 197, 6, 6); } if ($rating > 100) { echo "Overload Error!"; exit; } $back = ImageColorAllocate($image, 255, 255, 255); $border = ImageColorAllocate($image, 151, 151, 151); ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back); ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill); ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border); imagePNG($image); imagedestroy($image); }
function drawRating() { $width = $_GET['width']; $height = $_GET['height']; if ($width == 0) { $width = 200; } if ($height == 0) { $height = 7; } $rating = $_GET['rating']; $ratingbar = $rating / 100 * $width - 2; $image = imagecreate($width, $height); $fill = ImageColorAllocate($image, 0, 255, 0); if ($rating > 49) { $fill = ImageColorAllocate($image, 255, 255, 0); } if ($rating > 74) { $fill = ImageColorAllocate($image, 255, 128, 0); } if ($rating > 89) { $fill = ImageColorAllocate($image, 255, 0, 0); } $back = ImageColorAllocate($image, 205, 205, 205); $border = ImageColorAllocate($image, 0, 0, 0); ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back); ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill); ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border); imagePNG($image); imagedestroy($image); }
function weldMaps2PNG($urls, $filename, $encode = true) { if (!$urls || $urls == "") { $e = new mb_exception("weldMaps2PNG: no maprequests delivered"); } $url = explode("___", $urls); $obj1 = new stripRequest($url[0]); $width = $obj1->get("width"); $height = $obj1->get("height"); $image = imagecreatetruecolor($width, $height); $white = ImageColorAllocate($image, 255, 255, 255); ImageFilledRectangle($image, 0, 0, $width, $height, $white); for ($i = 0; $i < count($url); $i++) { $obj = new stripRequest($url[$i]); $url[$i] = $obj->setPNG(); $url[$i] = $obj->encodeGET($encode); $img = $this->loadpng($url[$i]); if ($img != false) { imagecopy($image, $img, 0, 0, 0, 0, $width, $height); @imagedestroy($img); } else { $e = new mb_exception("weldMaps2PNG: unable to load image: " . $url[$i]); } } imagepng($image, $filename); imagedestroy($image); }
function SaveLegend($url, $legend_filename) { if (!$url || $url == "") { $e = new mb_exception("SaveLegend: no legendurl delivered"); } $x = new connector($url); //save file in tmp folder to extract right size - sometimes the size could not be detected by url! if ($legendFileHandle = fopen($legend_filename, "w")) { fwrite($legendFileHandle, $x->file); fclose($legendFileHandle); $e = new mb_notice("SaveLegend: new legend file created: " . $legend_filename); } else { $e = new mb_exception("SaveLegend: legend file " . $legend_filename . " could not be created!"); } //get size of image $size = getimagesize($legend_filename); $width = $size[0]; $height = $size[1]; $image = imagecreatetruecolor($width, $height); $white = ImageColorAllocate($image, 255, 255, 255); ImageFilledRectangle($image, 0, 0, $width, $height, $white); //load image from url to create new image $img = $this->loadpng($url); if ($img != false) { imagecopy($image, $img, 0, 0, 0, 0, $width, $height); } else { $e = new mb_exception("SaveLegend: unable to load image: " . $url); } //save image to same filename as before imagepng($image, $legend_filename); imagedestroy($img); }
function drawRating($rating, $max, $type) { if ($type == 0) { $image = imagecreatetruecolor(102, 15); $back = ImageColorAllocate($image, 250, 250, 250); $border = ImageColorAllocate($image, 0, 0, 0); $fill = ImageColorAllocate($image, 0, 235, 0); ImageFilledRectangle($image, 0, 0, 101, 14, $back); ImageFilledRectangle($image, 1, 1, $rating / $max * 100, 14, $fill); ImageRectangle($image, 0, 0, 101, 14, $border); $textcolor = imagecolorallocate($image, 0, 0, 0); imagestring($image, 5, 35, 0, $rating / $max * 100 . '%', $textcolor); } else { if ($rating > $max) { $rating = $max; } $image = imagecreatetruecolor(10 * ($rating + 2) + 2, 15); $back = ImageColorAllocate($image, 250, 250, 250); $border = ImageColorAllocate($image, 0, 0, 0); $fill = ImageColorAllocate($image, 235, 0, 0); ImageFilledRectangle($image, 0, 0, 10 * ($rating + 2) + 1, 14, $back); ImageFilledRectangle($image, 1, 1, 10 * $rating, 14, $fill); ImageRectangle($image, 0, 0, 10 * $rating + 1, 14, $border); $textcolor = imagecolorallocate($image, 0, 0, 0); imagestring($image, 5, 10 * ($rating + 1), 0, $rating, $textcolor); } imagepng($image); imagedestroy($image); }
function weldOverview2PNG($url_overview, $url_extent, $filename) { if (!$url_overview || $url_overview == "") { $e = new mb_exception("weldOverview2PNG: no maprequests delivered"); } $url = $url_overview; $obj1 = new stripRequest($url); $width = $obj1->get("width"); $height = $obj1->get("height"); /* $e = new mb_exception("--------overview-----------------"); $e = new mb_exception("-----width ".$width." / height: ".$height."--------------------"); $e = new mb_exception("url_overview: ".$url_overview); $e = new mb_exception("url_extent: ".$url_extent); */ $image = imagecreatetruecolor($width, $height); $white = ImageColorAllocate($image, 255, 255, 255); ImageFilledRectangle($image, 0, 0, $width, $height, $white); //overview $obj = new stripRequest($url_overview); $xurl_overview = $obj->setPNG(); $xurl_overview = $obj->encodeGET(); $img = $this->loadpng($xurl_overview); if ($img != false) { imagecopy($image, $img, 0, 0, 0, 0, $width, $height); } else { $e = new mb_exception("weldMaps2PNG: unable to load image: " . $url_overview); } // rectangle - position of the map in the overview $objx = new stripRequest($url_extent); $ex_width = $objx->get("width"); $ex_height = $objx->get("height"); $extent = explode(",", $objx->get("BBOX")); $lowerleft = $this->makeRealWorld2mapPos($url_overview, round($extent[0]), round($extent[1])); $upperright = $this->makeRealWorld2mapPos($url_overview, $extent[2], $extent[3]); /* $e = new mb_exception("ex_width: " .$ex_width); $e = new mb_exception("ex_height: " . $ex_height); $e = new mb_exception("bbox:".$extent[0]."--".$extent[1]."--".$extent[2]."--------".$extent[3]); $e = new mb_exception("ll: " . $lowerleft[0]." / ".$lowerleft[1]); $e = new mb_exception("ur: " . $upperright[0]." / ".$upperright[1]); */ $lowerleft[0] = round($lowerleft[0]); $lowerleft[1] = round($lowerleft[1]); $upperright[0] = round($upperright[0]); $upperright[1] = round($upperright[1]); $red = ImageColorAllocate($image, 255, 0, 0); imageline($image, $lowerleft[0], $upperright[1], $upperright[0], $upperright[1], $red); imageline($image, $upperright[0], $upperright[1], $upperright[0], $lowerleft[1], $red); imageline($image, $upperright[0], $lowerleft[1], $lowerleft[0], $lowerleft[1], $red); imageline($image, $lowerleft[0], $lowerleft[1], $lowerleft[0], $upperright[1], $red); // black frame - size of the overview $black = ImageColorAllocate($image, 0, 0, 0); imageline($image, 0, 0, $width - 1, 0, $black); imageline($image, $width - 1, 0, $width - 1, $height - 1, $black); imageline($image, $width - 1, $height - 1, 0, $height - 1, $black); imageline($image, 0, $height - 1, 0, 0, $black); imagepng($image, $filename); imagedestroy($image); }
function drawRating($rating) { $width = $_GET['width']; $height = $_GET['height']; if ($width == 0) { $width = 102; } if ($height == 0) { $height = 10; } $rating = $_GET['rating']; $ratingbar = (($rating/100)*$width)-2; $image = imagecreate($width,$height); //colors $back = ImageColorAllocate($image,255,255,255); $border = ImageColorAllocate($image,0,0,0); $red = ImageColorAllocate($image,255,60,75); $fill = ImageColorAllocate($image,44,81,150); ImageFilledRectangle($image,0,0,$width-1,$height-1,$back); ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill); ImageRectangle($image,0,0,$width-1,$height-1,$border); imagePNG($image); imagedestroy($image); }
function ConvertToImage($content) { $imageFile = ".counter.png"; $relativePath = ".counter.png"; $noOfChars = strlen($content); $charHeight = ImageFontHeight(5); $charWidth = ImageFontWidth(5); $strWidth = $charWidth * $noOfChars; $strHeight = $charHeight; //15 padding $imgWidth = $strWidth + 15; $imgHeight = $strHeight + 15; $imgCenterX = $imgWidth / 2; $imgCenterY = $imgHeight / 2; $im = ImageCreate($imgWidth, $imgHeight); $script = ImageColorAllocate($im, 0, 255, 0); $outercolor = ImageColorAllocate($im, 99, 140, 214); $innercolor = ImageColorAllocate($im, 0, 0, 0); ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor); ImageFilledRectangle($im, 3, 3, $imgWidth - 4, $imgHeight - 4, $innercolor); //draw string $drawPosX = $imgCenterX - $strWidth / 2 + 1; $drawPosY = $imgCenterY - $strHeight / 2; ImageString($im, 5, $drawPosX, $drawPosY, $content, $script); //save image and return ImagePNG($im, $imageFile); return $relativePath; }
function bar_chart($question, $answers) { // define colors to draw the bars $colors = array(0xff6600, 0x9900, 0x3333cc, 0xff0033, 0xffff00, 0x66ffff, 0x9900cc); $total = array_sum($answers['votes']); // define spacing values and other magic numbers $padding = 5; $line_width = 20; $scale = $line_width * 7.5; $bar_height = 10; $x = $y = $padding; // allocate a large palette for drawing, since you don't know // the image length ahead of time $image = ImageCreateTrueColor(150, 500); ImageFilledRectangle($image, 0, 0, 149, 499, 0xe0e0e0); $black = 0x0; // print the question $wrapped = explode("\n", wordwrap($question, $line_width)); foreach ($wrapped as $line) { ImageString($image, 3, $x, $y, $line, $black); $y += 12; } $y += $padding; // print the answers for ($i = 0; $i < count($answers['answer']); $i++) { // format percentage $percent = sprintf('%1.1f', 100 * $answers['votes'][$i] / $total); $bar = sprintf('%d', $scale * $answers['votes'][$i] / $total); // grab color $c = $i % count($colors); // handle cases with more bars than colors $text_color = $colors[$c]; // draw bar and percentage numbers ImageFilledRectangle($image, $x, $y, $x + $bar, $y + $bar_height, $text_color); ImageString($image, 3, $x + $bar + $padding, $y, "{$percent}%", $black); $y += 12; // print answer $wrapped = explode("\n", wordwrap($answers['answer'][$i], $line_width)); foreach ($wrapped as $line) { ImageString($image, 2, $x, $y, $line, $black); $y += 12; } $y += 7; } // crop image by copying it $chart = ImageCreateTrueColor(150, $y); ImageCopy($chart, $image, 0, 0, 0, 0, 150, $y); // PHP 5.5+ supports // $chart = ImageCrop($image, array('x' => 0, 'y' => 0, // 'width' => 150, 'height' => $y)); // deliver image header('Content-type: image/png'); ImagePNG($chart); // clean up ImageDestroy($image); ImageDestroy($chart); }
private function createBase() { $this->image = imagecreatetruecolor($this->size[0], $this->size[1]); // Creation de l'image de sortie // Declaration couleur $blanc = imagecolorallocate($this->image, $this->background[0], $this->background[1], $this->background[2]); // Couleur de fond $fond = ImageFilledRectangle($this->image, 0, 0, imagesx($this->image), imagesy($this->image), $blanc); }
private function createImage() { $red = '0x' . substr($this->color, 1, 2); $green = '0x' . substr($this->color, 3, 2); $blue = '0x' . substr($this->color, 5, 2); $baseIMG = @imagecreatetruecolor($this->maxW, $this->maxH); $color = imagecolorallocate($baseIMG, $red, $green, $blue); ImageFilledRectangle($baseIMG, 0, 0, $this->maxW, $this->maxH, $color); $this->baseIMG = $baseIMG; }
function drawSampleImage() { echo 'drawSampleImage called'; $im = ImageCreate(200, 200); $white = ImageColorAllocate($im, 0xff, 0xff, 0xff); $black = ImageColorAllocate($im, 0x0, 0x0, 0x0); ImageFilledRectangle($im, 50, 50, 150, 150, $black); header('Content-Type: image/png'); ImagePNG($im); }
public function Plot($Coord) { list($CoordsX, $CoordsY) = map::ss2xy($Coord); $p1 = ($CoordsX - 1) * $this->tc + 1; $p2 = $CoordsY * $this->tc + 1; $p3 = $p1 + $this->tc - 2; $p4 = $p2 + $this->tc - 2; ImageFilledRectangle($this->im, $p1, $p2, $p3, $p4, $this->color); return $this; }
public function resample($src, $dst, $width = '', $height = '', $square = false) { if (is_file($dst)) { return; // unlink($dst); } $size = getimagesize($src); if (!$size[0] || !$size[1]) { return; } list($oldWidth, $oldHeight, $type) = getimagesize($src); $ext = $this->image_type_to_extension($type); $scale = min($width / $size[0], $height / $size[1]); // echo $scale; if ($scale == 1) { // return; } $newwidth = (int) ($size[0] * $scale); $newheight = (int) ($size[1] * $scale); if ($square) { $xpos = (int) (($width - $newwidth) / 2); $ypos = (int) (($height - $newheight) / 2); } else { $width = $newwidth; $height = $newheight; $xpos = 0; $ypos = 0; } $destImg = ImageCreateTrueColor($width, $height); $backColor = ImageColorAllocate($destImg, 255, 255, 255); ImageFilledRectangle($destImg, 0, 0, $width, $height, $backColor); // $sourceImg = ImageCreateFromJPEG ($src); switch ($ext) { case 'gif': $sourceImg = imagecreatefromgif($src); break; case 'png': $sourceImg = imagecreatefrompng($src); break; case 'jpg': case 'jpeg': $sourceImg = imagecreatefromjpeg($src); break; default: return false; break; } ImageCopyResampled($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth, $newheight, $size[0], $size[1]); imagejpeg($destImg, $dst, 70); $data['width'] = $width; $data['height'] = $height; return $data; }
function setup() { $this->map = array(); $nthis->umStarts = 0; $this->numBases = 0; $this->numPills = 0; $this->img = ImageCreate(255, 255); $this->pens = array(); $this->pens[0] = ImageColorAllocate($this->img, 179, 121, 15); /* BUILDING */ $this->pens[1] = ImageColorAllocate($this->img, 0, 255, 255); /* RIVER */ $this->pens[2] = ImageColorAllocate($this->img, 0, 128, 128); /* SWAMP */ $this->pens[3] = ImageColorAllocate($this->img, 128, 64, 0); /* CRATER */ $this->pens[4] = ImageColorAllocate($this->img, 0, 0, 0); /* ROAD */ $this->pens[5] = ImageColorAllocate($this->img, 0, 128, 0); /* FOREST */ $this->pens[6] = ImageColorAllocate($this->img, 234, 165, 123); /* RUBBLE */ $this->pens[7] = ImageColorAllocate($this->img, 0, 255, 0); /* GRASS */ $this->pens[8] = ImageColorAllocate($this->img, 223, 152, 19); /* SHOT_BUILDING */ $this->pens[9] = ImageColorAllocate($this->img, 0, 0, 121); /* BOAT */ $this->pens[10] = ImageColorAllocate($this->img, 0, 128, 128); /* SWAMP + MINE */ $this->pens[11] = ImageColorAllocate($this->img, 128, 64, 0); /* CRATER_MINE */ $this->pens[12] = ImageColorAllocate($this->img, 0, 0, 0); /* ROAD_MINE */ $this->pens[13] = ImageColorAllocate($this->img, 0, 128, 0); /* FOREST_MINE */ $this->pens[14] = ImageColorAllocate($this->img, 234, 165, 123); /* RUBBLE_MINE */ $this->pens[15] = ImageColorAllocate($this->img, 0, 255, 0); /* GrassMine */ $this->pens[16] = ImageColorAllocate($this->img, 0, 0, 255); /* DEEP_SEA */ $this->pens[18] = ImageColorAllocate($this->img, 255, 0, 0); /* PILLBOX */ $this->pens[17] = ImageColorAllocate($this->img, 255, 255, 0); /* BASE */ $this->pens[19] = ImageColorAllocate($this->img, 128, 128, 128); /* START */ ImageFilledRectangle($this->img, 0, 0, 255, 255, $this->pens[16]); $this->water = imagecolorexact($this->img, 0, 0, 255); }
/** * Create the transparent unitPng and return its URL * * @return string * @access private */ function _unitpng() { if (file_exists($this->_oboxUnitPngPath)) { return $this->_oboxUnitPngURL; } $im = ImageCreate(1, 1); $trans = ImageColorAllocate($im, 128, 128, 128); ImageColorTransparent($im, $trans); ImageFilledRectangle($im, 0, 0, 1, 1, $trans); $this->_makeUnitPngPath(); ImagePNG($im, $this->_oboxUnitPngPath); ImageDestroy($im); return $this->_oboxUnitURL; }
function showImage() { $noise = true; $nb_noise = 10; $image = imagecreatetruecolor($this->height, $this->width); $width = imagesx($image); $height = imagesy($image); $back = ImageColorAllocate($image, intval(rand(224, 255)), intval(rand(224, 255)), intval(rand(224, 255))); ImageFilledRectangle($image, 0, 0, $width, $height, $back); if ($noise) { for ($i = 0; $i < $nb_noise; $i++) { $size = intval(rand(6, 14)); $angle = intval(rand(0, 360)); $x = intval(rand(10, $width - 10)); $y = intval(rand(0, $height - 5)); $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224))); $text = chr(intval(rand(45, 250))); ImageTTFText($image, $size, $angle, $x, $y, $color, $this->get_font(), $this->code); } //$i = 0; $i < $nb_noise; $i++ } else { for ($i = 0; $i < $width; $i += 10) { $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224))); imageline($image, $i, 0, $i, $height, $color); } //$i = 0; $i < $width; $i += 10 for ($i = 0; $i < $height; $i += 10) { $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224))); imageline($image, 0, $i, $width, $i, $color); } //$i = 0; $i < $height; $i += 10 } for ($i = 0, $x = 5; $i < strlen($this->code); $i++) { $r = intval(rand(0, 128)); $g = intval(rand(0, 128)); $b = intval(rand(0, 128)); $color = ImageColorAllocate($image, $r, $g, $b); $shadow = ImageColorAllocate($image, $r + 128, $g + 128, $b + 128); $size = intval(rand(14, 19)); $angle = intval(rand(-20, 20)); $text = strtoupper(substr($this->code, $i, 1)); ImageTTFText($image, $size, $angle, $x + 7, 26, $shadow, $this->get_font(), $text); ImageTTFText($image, $size - 1, $angle + 2, $x + 5, 24, $color, $this->get_font(), $text); $x += $size + 2; } //$i = 0, $x = 5; $i < strlen($this->code); $i++ header('Content-type: image/jpeg'); imagejpeg($image); ImageDestroy($image); }
function create_avatar_img($data = '', $img_path = '', $img_url = '', $font_path = '') { $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '215', 'img_height' => '215', 'img_type' => 'png', 'font_path' => BASEPATH . 'fonts/texb.ttf', 'word_length' => 1, 'font_size' => 100, 'img_id' => ''); foreach ($defaults as $key => $val) { if (!is_array($data) && empty(${$key})) { ${$key} = $val; } else { ${$key} = isset($data[$key]) ? $data[$key] : $val; } } if ($img_path === '' or $img_url === '' or !is_dir($img_path) or !is_really_writable($img_path) or !extension_loaded('gd')) { return FALSE; } $im = function_exists('imagecreatetruecolor') ? imagecreatetruecolor($img_width, $img_height) : imagecreate($img_width, $img_height); $i = strtoupper(substr($word, 0, 1)); $r = rand(0, 255); $g = rand(0, 255); $b = rand(0, 255); $x = (imagesx($im) - $font_size * strlen($i)) / 2; $y = (imagesy($im) + ($font_size - $font_size * 0.25)) / 2; $bg = imagecolorallocate($im, $r, $g, $b); $tc = imagecolorallocate($im, 255, 255, 255); // Create the rectangle ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg); $use_font = $font_path !== '' && file_exists($font_path) && function_exists('imagettftext'); if ($use_font === FALSE) { $font_size > 5 && ($font_size = 5); imagestring($im, $font_size, $x, $y, $i, $tc); } else { // ($font_size > 30) && $font_size = 30; imagettftext($im, $font_size, 0, $x, $y, $tc, $font_path, $i); } // ----------------------------------- // Generate the image // ----------------------------------- $now = microtime(TRUE); $img_url = rtrim($img_url, '/') . '/'; if ($img_type == 'jpeg') { $img_filename = $now . '.jpg'; imagejpeg($im, $img_path . $img_filename); } elseif ($img_type == 'png') { $img_filename = $now . '.png'; imagepng($im, $img_path . $img_filename); } else { return FALSE; } $img = '<img ' . ($img_id === '' ? '' : 'id="' . $img_id . '"') . ' src="' . $img_url . $img_filename . '" style="width: ' . $img_width . '; height: ' . $img_height . '; border: 0;" alt=" " />'; ImageDestroy($im); return array('image' => $img, 'file_path' => $img_path . $img_filename, 'file_url' => $img_url . $img_filename, 'filename' => $img_filename); }
function make_captcha($noise = true) { $private_key = $this->generate_private(); $image = imagecreatetruecolor($this->lx, $this->ly); $back = ImageColorAllocate($image, intval(mt_rand(224, 255)), intval(mt_rand(224, 255)), intval(mt_rand(224, 255))); ImageFilledRectangle($image, 0, 0, $this->lx, $this->ly, $back); if ($noise) { // mt_rand characters in background with mt_random position, angle, color for ($i = 0; $i < $this->nb_noise; $i++) { $size = intval(mt_rand(6, 14)); $angle = intval(mt_rand(0, 360)); $x = intval(mt_rand(10, $this->lx - 10)); $y = intval(mt_rand(0, $this->ly - 5)); $color = imagecolorallocate($image, intval(mt_rand(160, 224)), intval(mt_rand(160, 224)), intval(mt_rand(160, 224))); $text = chr(intval(mt_rand(45, 250))); ImageTTFText($image, $size, $angle, $x, $y, $color, $this->font_file, $text); } } else { // mt_random grid color for ($i = 0; $i < $this->lx; $i += 10) { $color = imagecolorallocate($image, intval(mt_rand(160, 224)), intval(mt_rand(160, 224)), intval(mt_rand(160, 224))); imageline($image, $i, 0, $i, $this->ly, $color); } for ($i = 0; $i < $this->ly; $i += 10) { $color = imagecolorallocate($image, intval(mt_rand(160, 224)), intval(mt_rand(160, 224)), intval(mt_rand(160, 224))); imageline($image, 0, $i, $this->lx, $i, $color); } } // private text to read for ($i = 0, $x = 5; $i < $this->long; $i++) { $r = intval(mt_rand(0, 128)); $g = intval(mt_rand(0, 128)); $b = intval(mt_rand(0, 128)); $color = ImageColorAllocate($image, $r, $g, $b); $shadow = ImageColorAllocate($image, $r + 128, $g + 128, $b + 128); $size = intval(mt_rand(12, 17)); $angle = intval(mt_rand(-30, 30)); $text = strtoupper(substr($private_key, $i, 1)); ImageTTFText($image, $size, $angle, $x + 2, 26, $shadow, $this->font_file, $text); ImageTTFText($image, $size, $angle, $x, 24, $color, $this->font_file, $text); $x += $size + 2; } if ($this->imagetype == "jpg") { imagejpeg($image, $this->get_filename(), 100); } else { imagepng($image, $this->get_filename()); } ImageDestroy($image); }
function LoadJpeg($imgname) { $im = @ImageCreateFromJPEG($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = ImageCreate(150, 30); /* Create a blank image */ $bgc = ImageColorAllocate($im, 255, 255, 255); $tc = ImageColorAllocate($im, 0, 0, 0); ImageFilledRectangle($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ ImageString($im, 1, 5, 5, "Error {$imgname}", $tc); } return $im; }
public function draw() { $font = $this->_getFont(); $htexte = 'dg' . $this->getText(); $hdim = ImageTTFBBox($this->getSize(), 0, $font, $htexte); $wdim = ImageTTFBBox($this->getSize(), 0, $font, $this->getText()); $dx = max($wdim[2], $wdim[4]) - min($wdim[0], $wdim[6]) + ceil($this->getSize() / 8); $dy = max($hdim[1], $hdim[3]) - min($hdim[5], $hdim[7]) + ceil($this->getSize() / 8); $img = ImageCreate(max($dx, 1), max($dy, 1)); $noir = ImageColorAllocate($img, 0, 0, 0); $blanc = ImageColorAllocate($img, 255, 255, 255); $blanc = imagecolortransparent($img, $blanc); ImageFilledRectangle($img, 0, 0, $dx, $dy, $blanc); ImageTTFText($img, $this->getSize(), $angle, 0, -min($hdim[5], $hdim[7]), $noir, $font, $this->getText()); return $img; }
function make_captcha($noise = true, $private_key, $fpath) { $font_file = JPATH_ROOT . DS . 'components' . DS . 'com_socialnetworking' . DS . 'assets' . DS . 'Dustismo.ttf'; $image = imagecreatetruecolor(120, 30); $back = ImageColorAllocate($image, intval(rand(224, 255)), intval(rand(224, 255)), intval(rand(224, 255))); ImageFilledRectangle($image, 0, 0, 120, 30, $back); if ($noise) { // rand characters in background with random position, angle, color for ($i = 0; $i < 30; $i++) { $size = intval(rand(6, 14)); $angle = intval(rand(0, 360)); $x = intval(rand(10, 120 - 10)); $y = intval(rand(0, 30 - 5)); $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224))); $text = chr(intval(rand(45, 250))); ImageTTFText($image, $size, $angle, $x, $y, $color, $font_file, $text); } } else { // random grid color for ($i = 0; $i < 120; $i += 10) { $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224))); imageline($image, $i, 0, $i, 30, $color); } for ($i = 0; $i < 30; $i += 10) { $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224))); imageline($image, 0, $i, 120, $i, $color); } } // private text to read for ($i = 0, $x = 5; $i < 6; $i++) { $r = intval(rand(0, 128)); $g = intval(rand(0, 128)); $b = intval(rand(0, 128)); $color = ImageColorAllocate($image, $r, $g, $b); $shadow = ImageColorAllocate($image, $r + 128, $g + 128, $b + 128); $size = intval(rand(12, 17)); $angle = intval(rand(-30, 30)); $text = strtoupper(substr($private_key, $i, 1)); ImageTTFText($image, $size, $angle, $x + 2, 26, $shadow, $font_file, $text); ImageTTFText($image, $size, $angle, $x, 24, $color, $font_file, $text); $x += $size + 2; } imagepng($image, $fpath); ImageDestroy($image); }
function render() { $this->h = $this->w / 2; $im = imagecreatetruecolor($this->w, $this->h); $width = $this->w; $height = $this->h; $center_x = intval($width / 2); $center_y = intval($height / 2); //gauge color $bgcolor = ImageColorAllocate($im, 247, 247, 247); $extRing = ImageColorAllocate($im, 214, 214, 214); $blueRing = ImageColorAllocate($im, 70, 132, 238); $blueRingLine = ImageColorAllocate($im, 106, 114, 127); $arrowBody = ImageColorAllocate($im, 228, 114, 86); $arrowLine = ImageColorAllocate($im, 207, 74, 42); $redArc = ImageColorAllocate($im, 220, 57, 18); $yellowArc = ImageColorAllocate($im, 255, 153, 0); $black = ImageColorAllocate($im, 0, 0, 0); $white = ImageColorAllocate($im, 255, 255, 255); $gray = ImageColorAllocate($im, 190, 190, 190); $fontArial = PATH_THIRDPARTY . 'html2ps_pdf/fonts/arial.ttf'; ImageFilledRectangle($im, 0, 0, $width - 1, $height - 1, $white); ImageRectangle($im, 0, 0, $width - 1, $height - 1, $gray); //center coords $cX = intval($this->w / 2); //$cX = intval($this->w /4); $cY = intval($this->h / 2); //diameter for gauge $diameter = intval($this->h * 4 / 5); $this->renderGauge($im, $cX, $cY, $diameter); /* //center coords $cX = intval($this->w * 3/4); $cY = intval($this->h /2); //diameter for gauge $diameter = intval( $this->h * 4/5 ); $this->renderGauge($im, $cX, $cY, $diameter); */ Header("Content-type: image/png"); ImagePng($im); }
function resizing($maxX, $maxY, $src_file, $tag_file) { if (!file_exists($src_file)) { return false; } list($width, $height, $type, $attr) = getimagesize($src_file); if ($type == 1) { $src_img = imagecreatefromgif($src_file); } else { if ($type == 2) { $src_img = imagecreatefromjpeg($src_file); } else { if ($type == 3) { $src_img = imagecreatefrompng($src_file); } } } $sx = imagesx($src_img); $sy = imagesy($src_img); $xratio = $sx / $maxX; $yratio = $sy / $maxY; $ratio = max($xratio, $yratio); $targ_Y = $sy / $ratio; $targ_X = $sx / $ratio; $dst_img = ImageCreateTrueColor($targ_X, $targ_Y); $colorSetting = ImageColorAllocate($dst_img, 255, 255, 255); ImageFilledRectangle($dst_img, 0, 0, $maxX, $maxY, $colorSetting); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $targ_X, $targ_Y, $sx, $sy); if ($type == 1) { imagegif($dst_img, $tag_file, 100); } else { if ($type == 2) { imagejpeg($dst_img, $tag_file, 100); } else { if ($type == 3) { imagepng($dst_img, $tag_file, 100); } } } ImageDestroy($dst_img); ImageDestroy($src_img); return true; }
function createGistagramm($width, $heigth) { $image = @imagecreate($width, $heigth); $maxKey = findMaxKey($this->array); $maxValue = findMaxValue($this->array); ImageColorAllocate($image, 255, 255, 255); ImageLine($image, $this->align, $heigth - $this->align, $width - $this->align, $heigth - $this->align, 1); ImageLine($image, $this->align, $this->align, $this->align, $heigth - $this->align, 1); $widthRect = round(($width - 2 * $this->align) / ($maxKey + 1)) * $this->widthColumn; foreach ($this->array as $key => $value) { $color = getColor($image, $value, $maxValue); $heigthRect = round($value * ($heigth - 2 * $this->align) / $maxValue); $pos = round($key / ($maxKey + 1) * ($width - 2 * $this->align)) + $this->align; ImageFilledRectangle($image, $pos - $widthRect / 2, $heigth - $heigthRect, $pos + $widthRect / 2, $heigth - $this->align, $color); ImageString($image, 0, $pos - $widthRect / 2, $heigth - $heigthRect - 10, $value, 1); ImageString($image, 0, $pos - $widthRect / 2, $heigth - $this->align, $key, 1); } $this->image = $image; }
/** * 文字画像出力 **/ function outPNG($dir, $font, $text, $name) { $width = 80; $height = 90; $fontSize = 60; $fangle = 0; $img = imagecreate($width, $height); $black = ImageColorAllocate($img, 0x0, 0x0, 0x0); $white = ImageColorAllocate($img, 0xff, 0xff, 0xff); //imagealphablending($img, true); //imagesavealpha($img, true); ImageFilledRectangle($img, 0, 0, $width, $height, $white); imagecolortransparent($img, $white); $box = imagettfbbox($fontSize, 0, $font, $text); $x = 0; $y = 70; imageTTFText($img, $fontSize, $fangle, $x, $y, $black, $font, $text); $filename = $dir . "/" . $name . ".png"; imagepng($img, $filename); imagedestroy($img); }
function recopImage($imgSource, $ratio) { $largeurSource = imagesx($imgSource); $hauteurSource = imagesy($imgSource); $ratioSource = $largeurSource / $hauteurSource; if ($ratioSource != $ratio) { if ($ratioSource < $ratio) { $largeur = $hauteurSource * $ratio; $im = ImageCreateTrueColor($largeur, $hauteurSource); ImageFilledRectangle($im, 0, 0, $largeur, $hauteurSource, ImageColorAllocate($im, 255, 255, 255)); ImageCopyResampled($im, $imgSource, ($largeur - $largeurSource) / 2, 0, 0, 0, $largeurSource, $hauteurSource, $largeurSource, $hauteurSource); } else { $hauteur = $largeurSource / $ratio; $im = ImageCreateTrueColor($largeurSource, $hauteur); ImageFilledRectangle($im, 0, 0, $largeurSource, $hauteur, ImageColorAllocate($im, 255, 255, 255)); ImageCopyResampled($im, $imgSource, 0, ($hauteur - $hauteurSource) / 2, 0, 0, $largeurSource, $hauteurSource, $largeurSource, $hauteurSource); } return $im; } else { return $imgSource; } }
/** * Constructor, assumes you pass over two parameters: the first is a string with * different maprequests, each seperated by three underscores (___). * * Iteratively calls a method to generate temporary images which are welded together at once. * The generated image is saved to the filesystem under the name * passed over as second parameter to the constructor. * * @param <string> the maprequests seperated by three underscores */ function weldMaps2PNG($urls, $filename) { if (!$urls || $urls == "") { $e = new mb_exception("weldMaps2PNG: no maprequests delivered"); } // getting the array of urls $url = explode("___", $urls); // make url parameters accessible $obj1 = new stripRequest($url[0]); $width = $obj1->get("width"); $height = $obj1->get("height"); // create output image $image = imagecreatetruecolor($width, $height); // assign a white background color $white = ImageColorAllocate($image, 255, 255, 255); ImageFilledRectangle($image, 0, 0, $width, $height, $white); // iterate over each request for ($i = 0; $i < count($url); $i++) { $obj = new stripRequest($url[$i]); // $url[$i] = $obj->setPNG(); $url[$i] = $obj->encodeGET(); // get temporary image for this URL $img = $this->loadpng($url[$i]); if ($img != false) { // copy temporary image over already assigned images imagecopy($image, $img, 0, 0, 0, 0, $width, $height); imagedestroy($img); } else { $e = new mb_exception("weldMaps2PNG: unable to copy image: " . $url[$i]); } } // output the image to the filesystem /** * @todo different outputs? */ imagepng($image, $filename); imagedestroy($image); }
function drawRating() { if (isset($_GET['rating'])) { $rating = $_GET['rating']; } else { $rating = 0; } if (isset($_GET['width'])) { $width = $_GET['width']; } else { $width = 170; } if (isset($_GET['height'])) { $height = $_GET['height']; } else { $height = 5; } $ratingbar = $rating / 100 * $width - 2; $image = imagecreate($width, $height) or die("Cannot Create image"); $fill = ImageColorAllocate($image, 0, 255, 0); if ($rating > 49) { $fill = ImageColorAllocate($image, 255, 255, 0); } if ($rating > 74) { $fill = ImageColorAllocate($image, 255, 128, 0); } if ($rating > 89) { $fill = ImageColorAllocate($image, 255, 0, 0); } $back = ImageColorAllocate($image, 205, 205, 205); $border = ImageColorAllocate($image, 0, 0, 0); ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back); ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill); ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border); imagePNG($image); imagedestroy($image); }
function twHoleImgOrig($pfad, $datei) { //$pfad = "http://progtw.myftp.org/shirtbemaler/img/uploads/"; //$datei = "grins.jpg"; $dateiMitPfad = $pfad . $datei; if (stristr($datei, ".jpg") != false || stristr($datei, ".jpeg") != false) { $im = @imagecreatefromjpeg($dateiMitPfad); } if (stristr($datei, ".gif") != false) { $im = @imagecreatefromgif($dateiMitPfad); } if (stristr($datei, ".png") != false) { $im = @imagecreatefrompng($dateiMitPfad); } // Fehler-Bild if (!$im) { $im = ImageCreate(150, 30); $bgc = ImageColorAllocate($im, 255, 255, 255); $tc = ImageColorAllocate($im, 0, 0, 0); ImageFilledRectangle($im, 0, 0, 150, 30, $bgc); ImageString($im, 1, 5, 5, "Fehler beim Öffnen von: {$dateiMitPfad}", $tc); } return $im; }