public static function translucentWatermark($originalImage, $watermark, $saveFile = null, $outputFileTipe = 'jpg') { $tempFolder = "temp/"; //$fileRandomValue = 0; $cache = $tempFolder . $saveFile . '.' . $outputFileTipe; // Load the stamp and the photo to apply the watermark to if (strstr($originalImage, '.jpg') !== false) { $im = imagecreatefromjpeg($originalImage); } elseif (strstr($originalImage, '.png') !== false) { $im = imagecreatefrompng($originalImage); } // First we create our stamp image manually from GD $stamp = imagecreatetruecolor(100, 70); imagefilledrectangle($stamp, 0, 0, 99, 69, 0xff); imagefilledrectangle($stamp, 9, 9, 90, 60, 0xffffff); //$im = imagecreatefromjpeg('photo.jpeg'); imagestring($stamp, 5, 20, 20, 'libGD', 0xff); imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0xff); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // Merge the stamp onto our photo with an opacity of 50% imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50); // Save the image to file and free memory imagepng($im, $cache); imagedestroy($im); }
function getCode($num, $w, $h) { // 去掉了 0 1 O l 等 $str = "23456789abcdefghijkmnpqrstuvwxyz"; $code = ''; for ($i = 0; $i < $num; $i++) { $code .= $str[mt_rand(0, strlen($str) - 1)]; } //将生成的验证码写入session,备验证页面使用 $_SESSION["my_checkcode"] = $code; //创建图片,定义颜色值 Header("Content-type: image/PNG"); $im = imagecreate($w, $h); $black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); $gray = imagecolorallocate($im, 118, 151, 199); $bgcolor = imagecolorallocate($im, 235, 236, 237); //画背景 imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor); //画边框 imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray); //imagefill($im, 0, 0, $bgcolor); //在画布上随机生成大量点,起干扰作用; for ($i = 0; $i < 80; $i++) { imagesetpixel($im, rand(0, $w), rand(0, $h), $black); } //将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成 $strx = rand(5, 10); for ($i = 0; $i < $num; $i++) { $strpos = rand(1, 6); imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black); $strx += $w / 5; } imagepng($im); imagedestroy($im); }
/** * Displays the captcha image * * @access public * @param int $key Captcha key * @return mixed Captcha raw image data */ function image($key) { $value = Jaws_Utils::RandomText(); $result = $this->update($key, $value); if (Jaws_Error::IsError($result)) { $value = ''; } $bg = dirname(__FILE__) . '/resources/simple.bg.png'; $im = imagecreatefrompng($bg); imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255)); // Write it in a random position.. $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70); $x = 5; $y = 20; $text_length = strlen($value); for ($i = 0; $i < $text_length; $i++) { $fnt = rand(7, 10); $y = rand(6, 10); imagestring($im, $fnt, $x, $y, $value[$i], $darkgray); $x = $x + rand(15, 25); } header("Content-Type: image/png"); ob_start(); imagepng($im); $content = ob_get_contents(); ob_end_clean(); imagedestroy($im); return $content; }
/** * Processes incoming text */ public function action_index() { $this->request->headers['Content-type'] = 'image/png'; // Grab text and styles $text = arr::get($_GET, 'text'); $styles = $_GET; $hover = FALSE; try { // Create image $img = new PNGText($text, $styles); foreach ($styles as $key => $value) { if (substr($key, 0, 6) == 'hover-') { // Grab hover associated styles and override existing styles $hover = TRUE; $styles[substr($key, 6)] = $value; } } if ($hover) { // Create new hover image and stack it $hover = new PNGText($text, $styles); $img->stack($hover); } echo $img->draw(); } catch (Exception $e) { if (Kohana::config('pngtext.debug')) { // Dump error message in an image form $img = imagecreatetruecolor(strlen($e->getMessage()) * 6, 16); imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255)); imagestring($img, 2, 0, 0, $e->getMessage(), imagecolorallocate($img, 0, 0, 0)); echo imagepng($img); } } }
static function codeimage() { $image = imagecreatetruecolor(100, 30); $bgcolor = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $bgcolor); $code = ''; for ($i = 0; $i < 4; $i++) { $fontsize = 6; $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120)); $data = "abcdefghjkmnpqrstuvwxy3456789"; $fontcontent = substr($data, rand(1, strlen($data) - 1), 1); $code .= $fontcontent; $x = $i * 100 / 4 + rand(5, 10); $y = rand(5, 10); imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor); } for ($i = 0; $i < 200; $i++) { $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200)); imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor); } for ($i = 0; $i < 2; $i++) { $linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220)); imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor); } $return['code'] = $code; $return['image'] = $image; return $return; // header('content-type:image/png'); // imagepng($image); }
function imgcode($nums, $width, $high) { //去除了數字0和1 字母小寫O和L,為了避免辨識不清楚 //$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMOPQRSTUBWXYZ"; $str = "0123456789"; $code = ''; for ($i = 0; $i < $nums; $i++) { $code .= $str[mt_rand(0, strlen($str) - 1)]; } $_SESSION['captcha'] = $code; //建立圖示,設置寬度及高度與顏色等等條件 $image = imagecreate($width, $high); $black = imagecolorallocate($image, mt_rand(0, 200), mt_rand(0, 200), mt_rand(0, 200)); $border_color = imagecolorallocate($image, 21, 106, 235); $background_color = imagecolorallocate($image, 235, 236, 237); //建立圖示背景 imagefilledrectangle($image, 0, 0, $width, $high, $background_color); //建立圖示邊框 imagerectangle($image, 0, 0, $width - 1, $high - 1, $border_color); //在圖示布上隨機產生大量躁點 for ($i = 0; $i < 80; $i++) { imagesetpixel($image, rand(0, $width), rand(0, $high), $black); } $strx = rand(3, 8); for ($i = 0; $i < $nums; $i++) { $strpos = rand(1, 6); imagestring($image, 5, $strx, $strpos, substr($code, $i, 1), $black); $strx += rand(10, 30); } imagepng($image); imagedestroy($image); }
/** * Class constructor generates the CAPTCHA image. * * @return blob the image * @access public */ function __construct() { session_start(); $image = imagecreate($this->width, $this->height); $random_str = $this->gen_str($this->chars_nr); #md5( microtime() ); // md5 to generate the random string $result_str = substr($random_str, 0, $this->chars_nr); //trim $chars_nr digit $bg_color = imagecolorallocate($image, $this->background_color['red'], $this->background_color['green'], $this->background_color['blue']); // background color $tx_color = imagecolorallocate($image, $this->text_color['red'], $this->text_color['gree'], $this->text_color['blue']); // text color for ($i = 0; $i <= $this->lines; $i++) { $line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255)); //line color imageline($image, rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), $line_color); // Create lines on image } imagestring($image, 5, 20, 10, $result_str, $tx_color); // Draw a random string horizontally $_SESSION['key'] = $result_str; // Carry the data through session header("Content-type: image/png"); // Out out the image imagepng($image); // Output image to browser }
public function generateCaptcha() { //make image $im = imagecreatetruecolor($this->width, $this->height); //set background $bg_color = imagecolorallocate($im, mt_rand($this->bg_color_min, $this->bg_color_max), mt_rand($this->bg_color_min, $this->bg_color_max), mt_rand($this->bg_color_min, $this->bg_color_max)); //padding imagefill($im, 0, 0, $bg_color); //add lines for ($i = 0; $i < $this->lines; $i++) { //set color $line_color = imagecolorallocate($im, mt_rand($this->line_color_min, $this->line_color_max), mt_rand($this->line_color_min, $this->line_color_max), mt_rand($this->line_color_min, $this->line_color_max)); //draw line imageline($im, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $line_color); } //add pixels for ($i = 0; $i < $this->pixels; $i++) { //set color $pixels_color = imagecolorallocate($im, mt_rand($this->pixels_color_min, $this->pixels_color_max), mt_rand($this->pixels_color_min, $this->pixels_color_max), mt_rand($this->pixels_color_min, $this->pixels_color_max)); //draw pixels imagesetpixel($im, mt_rand(0, $this->width), mt_rand(0, $this->height), $pixels_color); } //get captcha string $captcha = $this->generateString(); //set color of font $str_color = imagecolorallocate($im, mt_rand($this->font_color_min, $this->font_color_max), mt_rand($this->font_color_min, $this->font_color_max), mt_rand($this->font_color_min, $this->font_color_max)); //put string to picture imagestring($im, $this->font, ceil($this->width / 2) - 20, ceil($this->height / 2) - 10, $captcha, $str_color); //save or output imagepng($im); //destroy res imagedestroy($im); }
/** * Makes a graphical captcha from the provided text string * * @param string $captcha_text string to make image captcha from * @return string $data_url a data url containing the obfuscated image */ function makeGraphicalCaptcha($captcha_text) { $image = @imagecreatetruecolor(195, 35); // defines background color, random lines color and text color $bg_color = imagecolorallocate($image, mt_rand(0, 255), 255, 0); imagefill($image, 0, 0, $bg_color); $lines_color = imagecolorallocate($image, 0x99, 0xcc, 0x99); $text_color = imagecolorallocate($image, mt_rand(0, 255), 0, 255); // draws random lines for ($i = 0; $i < 4; $i++) { imageline($image, 0, rand(0, 35), 195, rand(0, 35), $lines_color); } $captcha_letter_array = str_split($captcha_text); foreach ($captcha_letter_array as $i => $captcha_letter) { imagesetthickness($image, 1); imagestring($image, 5, 5 + $i * 35, rand(2, 14), $captcha_letter, $text_color); } // creates image ob_start(); imagejpeg($image); $image_data = ob_get_contents(); ob_end_clean(); $data_url = "data:image/jpeg;base64," . base64_encode($image_data); imagedestroy($image); return $data_url; }
function imagecharx($img, $char, $x0, $y0, $ylist) { global $bk_color, $fg_color; $da = @imagecreate(10, 20) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($da, $bk_color[0], $bk_color[1], $bk_color[2]); $text_color = imagecolorallocate($da, $fg_color[0], $fg_color[1], $fg_color[2]); $color = imagecolorallocate($img, $fg_color[0], $fg_color[1], $fg_color[2]); $arg = rand(0, 18) / 100.0 * pi(); imagestring($da, 18, 0, 0, $char, $text_color); for ($i = 0; $i < 200; $i++) { $y = @floor($i / 10); $x = $i % 10; $point_color = imagecolorat($da, $x, $y); if ($point_color == $text_color) { for ($j = 0; $j < 12; $j++) { $dx = 0; $dy = 0; $p = 6; for ($s = 0; $s < $p; $s++) { $dx += rand(0, 1000 / $p) / 100; $dy += rand(0, 1000 / $p) / 100; } $xx = $x * 5 + $dx - 25; $yy = $y * 5 + $dy - 50; $x1 = cos($arg) * $xx - sin($arg) * $yy + 25; $y1 = sin($arg) * $xx + cos($arg) * $yy + 50; imagesetpixel($img, $x0 + $x1, $y0 + $y1, $color); } } } imagedestroy($da); }
function create_image() { header("Content-Type: image/png"); $image = imagecreatetruecolor(200, 50) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($image, 0, 0, 0); $text_color = imagecolorallocate($image, 122, 111, 255); $line_color = imagecolorallocate($image, 64, 64, 64); $pixel_color = imagecolorallocate($image, 0, 0, 255); imagefilledrectangle($image, 0, 0, 200, 50, $background_color); for ($i = 0; $i < 3; $i++) { imageline($image, 0, rand(0, 255) % 50, 200, rand(0, 255) % 50, $line_color); } for ($i = 0; $i < 1000; $i++) { imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color); } $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $len = strlen($letters); $letter = $letters[rand(0, $len - 1)]; # $text_color = imagecolorallocate($image, 0, 0, 0); $word = ""; for ($i = 0; $i < 6; $i++) { $letter = $letters[rand(0, $len - 1)]; imagestring($image, 7, 5 + $i * 30, 20, $letter, $text_color); $word .= $letter; } $_SESSION['solution'] = $word; imagepng($image); imagedestroy($image); }
protected function createImage($width, $height) { $im = imagecreate($width, $height); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "Простая Текстовая Строка", $text_color); imagepng($im, $this->tmpFile); }
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 getCode($num, $w, $h) { $code = ""; for ($i = 0; $i < $num; $i++) { $code .= rand(0, 9); } //4位验证码也可以用rand(1000,9999)直接生成 //将生成的验证码写入session,备验证页面使用 $_SESSION['yzm'] = $code; //setcookie("mimi", md5($code), time()+1200); //创建图片,定义颜色值 Header("Content-type: image/PNG"); $im = imagecreate($w, $h); $black = imagecolorallocate($im, 255, 0, 63); $gray = imagecolorallocate($im, 200, 200, 200); $bgcolor = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $bgcolor); //画边框 //imagerectangle($im, 0, 0, $w-1, $h-1, $black); //在画布上随机生成大量黑点,起干扰作用; for ($i = 0; $i < 10; $i++) { imagesetpixel($im, rand(0, $w), rand(0, $h), $black); } //将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成 $strx = rand(1, 3); for ($i = 0; $i < $num; $i++) { $strpos = rand(2, 6); imagestring($im, 5, $strx, $strpos, substr($code, $i, 1), $black); $strx += rand(8, 12); } imagepng($im); imagedestroy($im); }
function create_image() { // *** Generate a passcode using md5 // (it will be all lowercase hex letters and numbers *** $md5 = md5(rand(0, 9999)); $pass = substr($md5, 10, 5); // *** Set the session cookie so we know what the passcode is *** $_SESSION["pass"] = $pass; // *** Create the image resource *** $image = ImageCreatetruecolor(100, 20); // *** We are making two colors, white and black *** $clr_white = ImageColorAllocate($image, 255, 255, 255); $clr_black = ImageColorAllocate($image, 0, 0, 0); // *** Make the background black *** imagefill($image, 0, 0, $clr_black); // *** Set the image height and width *** imagefontheight(15); imagefontwidth(15); // *** Add the passcode in white to the image *** imagestring($image, 5, 30, 3, $pass, $clr_white); // *** Throw in some lines to trick those cheeky bots! *** imageline($image, 5, 1, 50, 20, $clr_white); imageline($image, 60, 1, 96, 20, $clr_white); // *** Return the newly created image in jpeg format *** return imagejpeg($image); // *** Just in case... *** imagedestroy($image); }
function create_captcha($width = 60, $height = 32) { session_start(); //生成验证码图片 Header("Content-type: image/PNG"); $im = imagecreate($width, $height); // width and height of image $back = ImageColorAllocate($im, 245, 245, 245); // specify background color imagefill($im, 0, 0, $back); // fill the background color into image $vcodes = ""; srand((double) microtime() * 1000000); //生成4位数字 for ($i = 0; $i < 4; $i++) { $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255)); // 生成随机颜色 $authnum = rand(1, 9); $vcodes .= $authnum; imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font); } for ($i = 0; $i < 100; $i++) { // interuppting $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imagesetpixel($im, rand() % 70, rand() % 30, $randcolor); // 画像素点函数 } ImagePNG($im); ImageDestroy($im); $_SESSION['captcha'] = $vcodes; }
function create_image() { $image = imagecreatetruecolor(200, 50); $background_color = imagecolorallocate($image, 255, 255, 255); imagefilledrectangle($image, 0, 0, 200, 50, $background_color); $line_color = imagecolorallocate($image, 255, 0, 255); for ($i = 0; $i < 10; $i++) { imageline($image, 0, rand() % 50, 200, rand() % 25, $line_color); } $pixel_color = imagecolorallocate($image, 255, 0, 255); for ($i = 0; $i < 1000; $i++) { imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color); } $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; $len = strlen($letters); $letter = $letters[rand(0, $len - 1)]; $text_color = imagecolorallocate($image, 0, 0, 0); $word = ""; for ($i = 0; $i < 6; $i++) { $letter = $letters[rand(0, $len - 1)]; imagestring($image, 5, 5 + $i * 30, 20, $letter, $text_color); $word .= $letter; } $_SESSION['security_key'] = $word; imagepng($image); }
/** * +---------------------------------------------------------- * 图片上传的处理函数 * +---------------------------------------------------------- */ function create_captcha() { $word = $this->create_word(); // 把验证码字符串写入session $_SESSION['captcha'] = md5($word . DOU_SHELL); // 绘制基本框架 $im = imagecreatetruecolor($this->captcha_width, $this->captcha_height); $bg_color = imagecolorallocate($im, 235, 236, 237); imagefilledrectangle($im, 0, 0, $this->captcha_width, $this->captcha_height, $bg_color); $border_color = imagecolorallocate($im, 118, 151, 199); imagerectangle($im, 0, 0, $this->captcha_width - 1, $this->captcha_height - 1, $border_color); // 添加干扰 for ($i = 0; $i < 5; $i++) { $rand_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagearc($im, mt_rand(-$this->captcha_width, $this->captcha_width), mt_rand(-$this->captcha_height, $this->captcha_height), mt_rand(30, $this->captcha_width * 2), mt_rand(20, $this->captcha_height * 2), mt_rand(0, 360), mt_rand(0, 360), $rand_color); } for ($i = 0; $i < 50; $i++) { $rand_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($im, mt_rand(0, $this->captcha_width), mt_rand(0, $this->captcha_height), $rand_color); } // 生成验证码图片 $text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); imagestring($im, 6, 18, 5, $word, $text_color); // header header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate"); header("Content-type: image/png;charset=utf-8"); /* 绘图结束 */ imagepng($im); imagedestroy($im); return true; }
public function index() { header("content-type:image/gif"); $this->load->library('session'); $width = 60; $height = 30; $img = imagecreatetruecolor($width, $height); $white = imagecolorallocate($img, 255, 255, 255); $color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255)); $str = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $code = ""; for ($i = 0; $i < 5; $i++) { $code .= $str[rand(0, strlen($str) - 1)]; } $this->session->set_userdata(array('myCode' => strtolower($code))); imagefilledrectangle($img, 0, 0, 60, 30, $color); for ($i = 0; $i < 100; $i++) { imagesetpixel($img, rand(0, 60), rand(0, 30), imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255))); } for ($i = 0; $i < 10; $i++) { imageline($img, rand(0, 60), rand(0, 30), rand(0, 60), rand(0, 30), imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255))); } imagestring($img, 5, 10, 5, $code, $white); return imagegif($img); //imagedestroy($img); }
function getCode($w, $h) { $im = imagecreate($w, $h); //imagecolorallocate($im, 14, 114, 180); // background color $red = imagecolorallocate($im, 255, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); $num1 = rand(1, 20); $num2 = rand(1, 20); $_SESSION['helloweba_math'] = $num1 + $num2; $gray = imagecolorallocate($im, 118, 151, 199); $black = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); //画背景 imagefilledrectangle($im, 0, 0, 100, 24, $black); //在画布上随机生成大量点,起干扰作用; for ($i = 0; $i < 80; $i++) { imagesetpixel($im, rand(0, $w), rand(0, $h), $gray); } imagestring($im, 5, 5, 4, $num1, $red); imagestring($im, 5, 30, 3, "+", $red); imagestring($im, 5, 45, 4, $num2, $red); imagestring($im, 5, 70, 3, "=", $red); imagestring($im, 5, 80, 2, "?", $white); header("Content-type: image/png"); imagepng($im); imagedestroy($im); }
function graph_error($string) { global $vars, $config, $debug, $graphfile; $vars['bg'] = 'FFBBBB'; include 'includes/graphs/common.inc.php'; $rrd_options .= ' HRULE:0#555555'; $rrd_options .= " --title='" . $string . "'"; rrdtool_graph($graphfile, $rrd_options); if ($height > '99') { shell_exec($rrd_cmd); d_echo('<pre>' . $rrd_cmd . '</pre>'); if (is_file($graphfile) && !$debug) { header('Content-type: image/png'); $fd = fopen($graphfile, 'r'); fpassthru($fd); fclose($fd); unlink($graphfile); exit; } } else { if (!$debug) { header('Content-type: image/png'); } $im = imagecreate($width, $height); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0)); imagepng($im); imagedestroy($im); exit; } }
/** * @param string $path * @param int $maxX * @param int $maxY * @param boolean $scalingup * @param \OC\Files\View $fileview * @return bool|\OC_Image */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); //don't create previews of empty text files if (trim($content) === '') { return false; } $lines = preg_split("/\r\n|\n|\r/", $content); $fontSize = 5; //5px $lineSize = ceil($fontSize * 1.25); $image = imagecreate($maxX, $maxY); imagecolorallocate($image, 255, 255, 255); $textColor = imagecolorallocate($image, 0, 0, 0); foreach ($lines as $index => $line) { $index = $index + 1; $x = (int) 1; $y = (int) ($index * $lineSize) - $fontSize; imagestring($image, 1, $x, $y, $line, $textColor); if ($index * $lineSize >= $maxY) { break; } } $image = new \OC_Image($image); return $image->valid() ? $image : false; }
public function testUploadFile() { $album = $this->Album->init(); $tmp_file = "/tmp/111111111.jpg"; # Generate custom image to test upload $im = imagecreatetruecolor(120, 20); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); imagejpeg($im, $tmp_file); # Generate path to save file $file_path = $this->Picture->generateFilePath($album['Album']['id'], 'picturetests.jpg'); $file = new File($file_path); # Get resize options $resize_attrs = $this->Picture->getResizeToSize(); # Upload and save $should_return_3 = $this->Picture->uploadFile($file_path, $album['Album']['id'], 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true); # File was saved? $this->assertEqual(3, $should_return_3); # File was uploaded? $this->assertTrue($file->exists()); # Should rise exception try { $this->Picture->uploadFile($file_path, null, 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true); } catch (ForbiddenException $e) { $this->assertEqual($e->getMessage(), "The album ID is required"); } }
public function __construct($type = 1, $size = 6) { Oraculum_Request::init_sess(); if (is_null(Oraculum_Request::sess("captcha"))) { if ($type == 3) { $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $max = 61; } elseif ($type == 2) { $letters = 'abcdefghijklmnopqrstuvwxyz0123456789'; $max = 35; } else { $letters = '0123456789'; $max = 9; } $string = NULL; for ($i = 0; $i < $size; $i++) { $string .= $letters[mt_rand(0, $max)]; } Oraculum_Request::setsess("captcha", $string); } else { $string = Oraculum_Request::sess("captcha"); } $img = imagecreate(10 * $size, 25); $backcolor = imagecolorallocate($img, 255, 255, 255); $textcolor = imagecolorallocate($img, 00, 00, 00); imagefill($img, 0, 0, $backcolor); imagestring($img, 10, 0, 5, $string, $textcolor); header("Content-type: image/jpeg"); imagejpeg($img); }
/** * Adds to the PNG image object, the data related to a row in the GIS dataset. * * @param string $spatial GIS LINESTRING object * @param string $label Label for the GIS LINESTRING object * @param string $line_color Color for the GIS LINESTRING object * @param array $scale_data Array containing data related to scaling * @param image $image Image object * * @return the modified image object */ public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image) { // allocate colors $black = imagecolorallocate($image, 0, 0, 0); $red = hexdec(substr($line_color, 1, 2)); $green = hexdec(substr($line_color, 3, 2)); $blue = hexdec(substr($line_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); // Trim to remove leading 'LINESTRING(' and trailing ')' $linesrting = substr($spatial, 11, strlen($spatial) - 12); $points_arr = $this->extractPoints($linesrting, $scale_data); foreach ($points_arr as $point) { if (!isset($temp_point)) { $temp_point = $point; } else { // draw line section imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color); $temp_point = $point; } } // print label if applicable if (isset($label) && trim($label) != '') { imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black); } return $image; }
function echo_check_image($str, $width, $height, $background_color, $text_color, $grid_color) { $number = $str; $background_color = str_replace("#", "", $background_color); $text_color = str_replace("#", "", $text_color); $grid_color = str_replace("#", "", $grid_color); // WebColor -> RGB $BR = hexdec(substr($background_color, 0, 2)); $BG = hexdec(substr($background_color, 2, 2)); $BB = hexdec(substr($background_color, 4, 2)); $TR = hexdec(substr($text_color, 0, 2)); $TG = hexdec(substr($text_color, 2, 2)); $TB = hexdec(substr($text_color, 4, 2)); $GR = hexdec(substr($grid_color, 0, 2)); $GG = hexdec(substr($grid_color, 2, 2)); $GB = hexdec(substr($grid_color, 4, 2)); $im = imagecreate($width, $height) or die("Cannot Initialize new GD image stream"); header("Content-type: image/png"); $background_color = imagecolorallocate($im, $BR, $BG, $BB); $text_color = imagecolorallocate($im, $TR, $TG, $TB); $grid_color = imagecolorallocate($im, $GR, $GG, $GB); image_random_grid($im, $width, $height, 5, $grid_color); imagestring($im, rand(4, 6), rand(5, 15), rand(1, 3), $number, $text_color); imagepng($im); imagedestroy($im); }
function draw_bar_graph($width, $height, $data, $max_value, $filename) { // Create the empty graph image $img = imagecreatetruecolor($width, $height); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 255, 255, 255); // white $bar_color = imagecolorallocate($img, 0, 0, 0); // black $border_color = imagecolorallocate($img, 192, 192, 192); // light gray // Fill the background imagefilledrectangle($img, 0, 0, $width, $height, $bg_color); // Draw the bars $bar_width = $width / (count($data) * 2 + 1); for ($i = 0; $i < count($data); $i++) { imagefilledrectangle($img, $i * $bar_width * 2 + $bar_width, $height, $i * $bar_width * 2 + $bar_width * 2, $height - $height / $max_value * $data[$i][1], $bar_color); imagestringup($img, 5, $i * $bar_width * 2 + $bar_width, $height - 5, $data[$i][0], $text_color); } // Draw a rectangle around the whole thing imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color); // Draw the range up the left side of the graph for ($i = 1; $i <= $max_value; $i++) { imagestring($img, 5, 0, $height - $i * ($height / $max_value), $i, $bar_color); } // Write the graph image to a file imagepng($img, $filename, 5); imagedestroy($img); }
function create_image() { // hash: là mật mã $md5_hash = md5(rand(0, 999)); // rand phat sinh 1 số từ 0 - 999 // md5 sẽ mã hóa 1 số thành 1 số khác đến 32 ký tự $security_code = substr($md5_hash, 15, 4); // substr lấy 1 chuỗi con trong md5_hash, lấy từ ký tự thứ 15 và lấy 5 ký tự $_SESSION['security_code'] = $security_code; $width = 100; //Khai báo kích thước captcha $height = 30; $image = imagecreate($width, $height); $while = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); $red = imagecolorallocate($image, 255, 255, 0); imagefill($image, 0, 0, $black); imagestring($image, 5, 30, 6, $security_code, $while); // 5 font size // 30 khoảng cách bên trái //khoảng cách từ trên xuống $captcha = imagecreatefrompng('captcha1.png'); $font = 'arial.ttf'; imagettftext($captcha, 23, 6, 20, 38, $black, $font, $security_code); header("Content-Type:image/jpeg"); // chuyển trang web thành dạng hình jpg imagejpeg($captcha); //Tạo hình imagedestroy($captcha); // Hủy hình gốc vì đã tạo thành trang }
public function getCanvas() { $date = zbx_date2str(DATE_TIME_FORMAT_SECONDS); imagestring($this->canvas, 1, $this->width - 120, $this->height - 12, $date, $this->getColor('gray')); imagestringup($this->canvas, 1, $this->width - 10, $this->height - 50, ZABBIX_HOMEPAGE, $this->getColor('gray')); return $this->canvas; }
/** * Generates image * * @param string $sMac verification code * * @return null */ function generateVerificationImg($sMac) { $iWidth = 80; $iHeight = 18; $iFontSize = 14; if (function_exists('imagecreatetruecolor')) { // GD2 $oImage = imagecreatetruecolor($iWidth, $iHeight); } elseif (function_exists('imagecreate')) { // GD1 $oImage = imagecreate($iWidth, $iHeight); } else { // GD not found return; } $iTextX = ($iWidth - strlen($sMac) * imagefontwidth($iFontSize)) / 2; $iTextY = ($iHeight - imagefontheight($iFontSize)) / 2; $aColors = array(); $aColors["text"] = imagecolorallocate($oImage, 0, 0, 0); $aColors["shadow1"] = imagecolorallocate($oImage, 200, 200, 200); $aColors["shadow2"] = imagecolorallocate($oImage, 100, 100, 100); $aColors["background"] = imagecolorallocate($oImage, 255, 255, 255); $aColors["border"] = imagecolorallocate($oImage, 0, 0, 0); imagefill($oImage, 0, 0, $aColors["background"]); imagerectangle($oImage, 0, 0, $iWidth - 1, $iHeight - 1, $aColors["border"]); imagestring($oImage, $iFontSize, $iTextX + 1, $iTextY + 0, $sMac, $aColors["shadow2"]); imagestring($oImage, $iFontSize, $iTextX + 0, $iTextY + 1, $sMac, $aColors["shadow1"]); imagestring($oImage, $iFontSize, $iTextX, $iTextY, $sMac, $aColors["text"]); header('Content-type: image/png'); imagepng($oImage); imagedestroy($oImage); }