function MyImageBlur($im, $pct) { // w00t. my very own blur function // in GD2, there's a gaussian blur function. smarmy bastards. ;-) $width = imagesx($im); $height = imagesy($im); $temp_im = ImageCreate($width, $height); $bg = ImageColorAllocate($temp_im, 255, 255, 255); // preserves transparency if in orig image ImageColorTransparent($temp_im, $bg); // fill bg ImageFill($temp_im, 0, 0, $bg); $distance = 1; // emboss: ImageCopyMerge($temp_im, $im, 0, 0, $distance, $distance, $width, $height, $pct); ImageCopyMerge($im, $temp_im, -$distance, -$distance, 0, 0, $width, $height, $pct); ImageFill($temp_im, 0, 0, $bg); ImageCopyMerge($temp_im, $im, 0, $distance, $distance, 0, $width, $height, $pct); ImageCopyMerge($im, $temp_im, $distance, 0, 0, $distance, $width, $height, $pct); // blur: ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, $pct); ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, $pct); ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height, $pct); ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width, $height, $pct); // remove temp image ImageDestroy($temp_im); return $im; }
function generateImage($token) { $iFont = 5; // Font ID $iSpacing = 2; // Spacing between characters $iDisplacement = 5; // Vertical chracter displacement // Establish font metric and image size $iCharWidth = ImageFontWidth($iFont); $iCharHeight = ImageFontHeight($iFont); $iWidth = strlen($token) * ($iCharWidth + $iSpacing); $iHeight = $iCharHeight + 2 * $iDisplacement; // Create the image $pic = ImageCreate($iWidth, $iHeight); // Allocate a background and foreground colour $col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200)); for ($x = 0; $x < $iWidth; $x += 2) { for ($y = 0; $y < $iHeight; $y += 2) { ImageSetPixel($pic, $x, $y, $col['grey']); } } $iX = 1; for ($i = 0; $i < strlen($token); $i++) { ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']); $iX += $iCharWidth + $iSpacing; } $iX = 2; $c = array('blue', 'green', 'red', 'purple'); for ($i = 0; $i < strlen($token); $i++) { $colour = $c[rand(0, count($c) - 1)]; ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]); $iX += $iCharWidth + $iSpacing; } for ($x = 1; $x < $iWidth; $x += 4) { for ($y = 1; $y < $iHeight; $y += 4) { ImageSetPixel($pic, $x, $y, $col['white']); } } // Draw some lines for ($i = 0; $i < 4; $i++) { ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']); } ob_start(); if (function_exists('imagejpeg')) { ImageJPEG($pic); } elseif (function_exists('imagepng')) { ImagePNG($pic); } else { ob_end_clean(); return false; } $data = ob_get_contents(); ob_end_clean(); ImageDestroy($pic); return $data; }
function init_resultat_election() { global $image, $blanc, $noir, $gris, $gris2; header("Content-type: image/png"); $annee = $_REQUEST[annee]; $genre = $_REQUEST[genre]; $type = $_REQUEST[type]; $lesMiss = selectDbMiss($annee, $genre, $type, "", true); usort($lesMiss, "callback_sort_nb_votes"); $nb = count($lesMiss); $hauteur = TAILLE_BARRE * $nb; $largeur = TAILLE_HAUTEUR; $image = ImageCreate($hauteur, $largeur); // On passe en blanc le fond de l'image $blanc = imagecolorallocate($image, 255, 255, 255); $noir = imagecolorallocate($image, 0, 0, 0); $gris = ImageColorAllocate($image, 190, 190, 190); $gris2 = ImageColorAllocate($image, 140, 140, 140); imagefilledrectangle($image, 0, 0, $largeur, $hauteur, $blanc); $total_votes = nombre_votes_db($annee, $genre, $type); dessine_nom_results_miss($lesMiss, $total_votes); // Génération de l'image ImagePng($image); // Desctruction de l'image ImageDestroy($image); }
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $wh = false) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2 * $outerFrame; $imgH = $h + 2 * $outerFrame; $base_image = ImageCreate($imgW, $imgH); $col[0] = ImageColorAllocate($base_image, 255, 255, 255); $col[1] = ImageColorAllocate($base_image, 0, 0, 0); imagefill($base_image, 0, 0, $col[0]); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); } } } $www = $imgW * $pixelPerPoint; $hhh = $imgH * $pixelPerPoint; if (is_array($wh)) { $www = $wh[0]; $hhh = $wh[1]; } $target_image = ImageCreate($www, $hhh); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $www, $hhh, $imgW, $imgH); ImageDestroy($base_image); return $target_image; }
/** * 把图片生成缩略图1 * @param string $srcFile 源文件 * @param string $dstFile 目标文件 * @param int $dstW 目标图片宽度 * @param int $dstH 目标文件高度 * @param string $dstFormat 目标文件生成的格式, 有png和jpg两种格式 * @return 错误返回错误对象 */ public static function makeThumb1($srcFile, $dstFile, $dstW, $dstH, $dstFormat = "png") { //打开图片 $data = GetImageSize($srcFile, &$info); switch ($data[2]) { case 1: $im = @ImageCreateFromGIF($srcFile); break; case 2: $im = @imagecreatefromjpeg($srcFile); break; case 3: $im = @ImageCreateFromPNG($srcFile); break; } if (!$im) { throw new TM_Exception(__CLASS__ . ": Create image failed"); } //设定图片大小 $srcW = ImageSX($im); $srcH = ImageSY($im); $ni = ImageCreate($dstW, $dstH); ImageCopyResized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH); //生成指定格式的图片 if ($dstFormat == "png") { imagepng($ni, $dstFile); } elseif ($dstFormat == "jpg") { ImageJpeg($ni, $dstFile); } else { imagepng($ni, $dstFile); } }
/** * $IMG_WIDTH = 100; //图像宽度 $IMG_HEIGHT = 23; //图像高度 $SESSION_VDCODE = ''; //Session变量名称 * $operator = '+-'; //运算符 */ public static function display($IMG_WIDTH = 70, $IMG_HEIGHT = 25, $SESSION_VDCODE = 'vdcode', $operator = '+') { $session_id = session_id(); if (empty($session_id)) { @session_start(); } $code = array(); $num1 = $code[] = mt_rand(1, 9); $code[] = '+'; //{mt_rand(0,1)}; $num2 = $code[] = mt_rand(1, 9); $codestr = implode('', $code); //eval("\$result = ".implode('',$code).";"); $code[] = '='; $_SESSION[$SESSION_VDCODE] = (int) $num1 + (int) $num2; $img = ImageCreate($IMG_WIDTH, $IMG_HEIGHT); ImageColorAllocate($img, mt_rand(230, 250), mt_rand(230, 250), mt_rand(230, 250)); $color = ImageColorAllocate($img, 0, 0, 0); $offset = 0; foreach ($code as $char) { $offset += 15; $txtcolor = ImageColorAllocate($img, mt_rand(0, 255), mt_rand(0, 150), mt_rand(0, 255)); ImageChar($img, mt_rand(3, 5), $offset, mt_rand(1, 5), $char, $txtcolor); } for ($i = 0; $i < 100; $i++) { $pxcolor = ImageColorAllocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); ImageSetPixel($img, mt_rand(0, $IMG_WIDTH), mt_rand(0, $IMG_HEIGHT), $pxcolor); } header('Content-type: image/png'); ImagePng($img); exit; }
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 guvenlik_resmi() { $sifre = substr(md5(rand(0, 999999999999)), -5); if ($sifre) { $this->session->set_userdata('koruma', $sifre); $yukseklik = 62; $genislik = 200; $resim = ImageCreate($genislik, $yukseklik); $siyah = ImageColorAllocate($resim, 0, 0, 0); $kirmizi = ImageColorAllocate($resim, 182, 16, 99); $beyaz = ImageColorAllocate($resim, 255, 255, 255); ImageFill($resim, 0, 0, $beyaz); $font = 'css/comic.ttf'; $font_boyut = 24; $sM = 30; $uM = 45; //kullanımı //resim adı, font boyutu, yazının açısı, yazının soldan margini, üstten margin, renk, font adı, şifrenin hangi digitinin yazılacağı bellirtiliyor imagettftext($resim, $font_boyut, rand(-45, 45), $sMa = $sM, $uM, rand(0, 255), $font, $sifre[0]); imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[1]); imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[2]); imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[3]); imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[4]); //ImageRectangle($resim, 0, 0, $genislik-1, $yukseklik-1, $kirmizi); imageline($resim, 0, $yukseklik / 2, $genislik, $yukseklik / 2, $kirmizi); imageline($resim, $genislik / 2, 0, $genislik / 2, $yukseklik, $kirmizi); header("Content-Type: image/png"); ImagePng($resim); ImageDestroy($resim); } exit; }
function PrintReport() { //建立画布大小 $this->IMAGE = ImageCreate($this->X, $this->Y); //设定画布背景色 $background = ImageColorAllocate($this->IMAGE, $this->R, $this->G, $this->B); if ($this->TRANSPARENT == "1") { //背影透明 Imagecolortransparent($this->IMAGE, $background); } else { //如不要透明时可填充背景色 ImageFilledRectangle($this->IMAGE, 0, 0, $this->X, $this->Y, $background); } //参数字体文小及颜色 $this->FONTCOLOR = ImageColorAllocate($this->IMAGE, 255 - $this->R, 255 - $this->G, 255 - $this->B); switch ($this->REPORTTYPE) { case "0": break; case "1": $this->imageColumnS(); break; case "2": $this->imageColumnH(); break; case "3": $this->imageLine(); break; case "4": $this->imageCircle(); break; } $this->printXY(); $this->printAll(); }
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $color = array()) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2 * $outerFrame; $imgH = $h + 2 * $outerFrame; $base_image = ImageCreate($imgW, $imgH); $col[0] = ImageColorAllocate($base_image, 255, 255, 255); if ($color) { $col[1] = ImageColorAllocate($base_image, $color[0], $color[1], $color[2]); } else { $col[1] = ImageColorAllocate($base_image, 0, 0, 0); } imagefill($base_image, 0, 0, $col[0]); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); } } } $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); ImageDestroy($base_image); return $target_image; }
function create_image() { //Let's generate a totally random string using md5 $md5_hash = md5(rand(0, 999)); //We don't need a 32 character long string so we trim it down to 5 $security_code = substr($md5_hash, 15, 5); //Set the session to store the security code $_SESSION["captchaCode"] = $security_code; //Set the image width and height $width = 100; $height = 20; //Create the image resource $image = ImageCreate($width, $height); //We are making three colors, white, black and gray $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); $grey = ImageColorAllocate($image, 204, 204, 204); //Make the background black ImageFill($image, 0, 0, $black); //Add randomly generated string in white to the image ImageString($image, 3, 30, 3, $security_code, $white); //Throw in some lines to make it a little bit harder for any bots to break ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey); imageline($image, 0, $height / 2, $width, $height / 2, $grey); imageline($image, $width / 2, 0, $width / 2, $height, $grey); //Tell the browser what kind of file is come in header("Content-Type: image/jpeg"); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); }
function captcha_create($text, $config) { global $cfg; // anzahl der zeichen $count = strlen($text); // schriftarten festlegen $ttf = $config["ttf"]; // schriftgroesse festlegen $ttf_size = $config["font"]["size"]; // schriftabstand rechts $ttf_x = $config["font"]["x"]; // schriftabstand oben $ttf_y = $config["font"]["y"]; // hintergrund erstellen $ttf_img = ImageCreate($count * 2 * $ttf_size, 2 * $ttf_size); // bgfarbe festlegen $bg_color = ImageColorAllocate($ttf_img, $config["bg_color"][0], $config["bg_color"][1], $config["bg_color"][2]); // textfarbe festlegen $font_color = ImageColorAllocate($ttf_img, $config["font_color"][0], $config["font_color"][1], $config["font_color"][2]); // schrift in bild einfuegen foreach (str_split($text) as $key => $character) { // schriftwinkel festlegen $ttf_angle = rand(-25, 25); // schriftarten auswaehlen $ttf_font = $ttf[rand(0, count($ttf) - 1)]; imagettftext($ttf_img, $ttf_size, $ttf_angle, $ttf_size * 2 * $key + $ttf_x, $ttf_y, $font_color, $ttf_font, $character); } // bild temporaer als datei ausgeben $captcha_crc = crc32($text . $config["randomize"]); $captcha_name = "captcha-" . $captcha_crc . ".png"; $captcha_path = $cfg["file"]["base"]["maindir"] . $cfg["file"]["base"]["new"]; imagepng($ttf_img, $captcha_path . $captcha_name); // bild loeschen imagedestroy($ttf_img); }
function reldis_createFile($filename, $uga_part, $agga_part) { $im_uga = @ImageCreateFromPng("good.png"); $im_agga = @ImageCreateFromPng("bad.png"); if (!$im_uga || !$im_agga) { die("Cannot Initialize new GD image stream"); } $width = imagesx($im_uga); $sum = $uga_part + $agga_part; $uga_part /= $sum; $agga_part /= $sum; $uga_part *= $width; $agga_part *= $width; $im = @ImageCreate($width, $width); $white = imagecolorallocate($im, 0xff, 0xff, 0xff); imagefill($im, 0, 0, $white); imagecolortransparent($im, $white); $left = 0; imagecopy($im, $im_uga, $left, 0, $left, 0, $uga_part + 1, $width); $left += $uga_part; imagecopy($im, $im_agga, $left, 0, $left, 0, $agga_part + 1, $width); header("Content-type: image/png"); imagepng($im, $filename); imagedestroy($im); }
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xffffff, $fore_color = 0x0) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2 * $outerFrame; $imgH = $h + 2 * $outerFrame; $base_image = ImageCreate($imgW, $imgH); // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) $r1 = round(($fore_color & 0xff0000) >> 16, 5); $b1 = round(($fore_color & 0xff00) >> 8, 5); $g1 = round($fore_color & 0xff, 5); // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) $r2 = round(($back_color & 0xff0000) >> 16, 5); $b2 = round(($back_color & 0xff00) >> 8, 5); $g2 = round($back_color & 0xff, 5); $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2); $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1); imagefill($base_image, 0, 0, $col[0]); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); } } } $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); ImageDestroy($base_image); return $target_image; }
function draw_captcha($security_code) { //Set the image width and height $width = 100; $height = 25; //Create the image resource $image = ImageCreate($width, $height); if (function_exists('imageantialias')) { imageantialias($image, true); } //We are making three colors, white, black and gray $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 15, 50, 15); $grey = ImageColorAllocate($image, 204, 204, 204); $ellipsec = ImageColorAllocate($image, 0, 100, 60); //Make the background black ImageFill($image, 0, 0, $black); imagefilledellipse($image, 56, 15, 30, 17, $ellipsec); //Add randomly generated string in white to the image ImageString($image, 5, 30, 4, $security_code, $white); //Throw in some lines to make it a little bit harder for any bots to break ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey); imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey); imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey); //Tell the browser what kind of file is come in header("Content-Type: image/jpeg"); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); }
/** * Generates the captcha image * * @since 4.0 * @access public * @param string * @return */ public function generate() { $id = $this->input->get('id', '', 'int'); // Load up the captcha object $captcha = EB::table('Captcha'); // Clear outdated keys $captcha->clear(); // load the captcha records. $captcha->load($id); if (!$captcha->id) { return false; } // @task: Generate a very random integer and take only 5 chars max. $hash = JString::substr(md5(rand(0, 9999)), 0, 5); $captcha->response = $hash; $captcha->store(); // Captcha width and height $width = 100; $height = 20; $image = ImageCreate($width, $height); $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); $gray = ImageColorAllocate($image, 204, 204, 204); ImageFill($image, 0, 0, $white); ImageString($image, 5, 30, 3, $hash, $black); ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray); imageline($image, 0, $height / 2, $width, $height / 2, $gray); imageline($image, $width / 2, 0, $width / 2, $height, $gray); header('Content-type: image/jpeg'); ImageJpeg($image); ImageDestroy($image); exit; }
function capcha($salt) { srand(time()); $md5_hash = md5(rand(0, 9999)); $security_code = substr($md5_hash, 25, 5); $enc = md5($security_code . $salt); $_SESSION['count'] = $enc; $secure = $_SESSION['count']; // echo "--------------------------$secure<br>"; $width = 50; $height = 24; $image = ImageCreate($width, $height); $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 100, 0); $grey = ImageColorAllocate($image, 204, 204, 204); ImageFill($image, 0, 0, $white); //Add randomly generated string in white to the image ImageString($image, 10, 4, 4, $security_code, $black); // ImageRectangle($image,0,16,$width-1,$height-1,$grey); imageline($image, 0, $height / 2, $width, $height / 2, $grey); imageline($image, $width / 2, 0, $width / 2, $height, $grey); header("Content-Type: image/jpeg"); header("Cache-Control: no-cache, must-revalidate"); ImageJpeg($image); ImageDestroy($image); }
/** * Generates a random captcha image * **/ function display($cachable = false, $urlparams = false) { // @TODO: Run some cleaning query here to clear the database. JTable::addIncludePath(DISCUSS_TABLES); $id = JRequest::getInt('captcha-id', ''); $captcha = DiscussHelper::getTable('Captcha'); // clearing the oudated keys. $captcha->clear(); // load the captcha records. $captcha->load($id); if (!$captcha->id) { return false; } // @task: Generate a very random integer and take only 5 chars max. $hash = JString::substr(md5(rand(0, 9999)), 0, 5); $captcha->response = $hash; $captcha->store(); // Captcha width and height $width = 100; $height = 20; $image = ImageCreate($width, $height); $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); $gray = ImageColorAllocate($image, 204, 204, 204); ImageFill($image, 0, 0, $white); ImageString($image, 5, 30, 3, $hash, $black); ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray); imageline($image, 0, $height / 2, $width, $height / 2, $gray); imageline($image, $width / 2, 0, $width / 2, $height, $gray); header('Content-type: image/jpeg'); ImageJpeg($image); ImageDestroy($image); exit; }
function create_image($string_captcha, $width = 130, $height = 35) { //Let's generate a totally random string using md5 // $md5_hash = md5(rand(0,999)); //We don't need a 32 character long string so we trim it down to 5 // $security_code = substr($md5_hash, 15, 5); $security_code = $string_captcha; /* ******************************************** Use this part if you need to Set the session to store the security code */ $_SESSION['security_code'] = $security_code; $CodeInd = 0; $arrSecCode = array(); $chars = preg_split('//', $security_code); $security_code = implode(" ", $chars); //Set the image width and height //$width = 130; //$height = 35; //Create the image resource $image = ImageCreate($width, $height); //We are making three colors, white, black and gray $arrB = array(0, 255, 129, 10, 48, 200, 186); $arrR = array(0, 255, 129, 111, 48, 210, 126); $arrG = array(0, 205, 139, 110, 48, 5, 186); $black = ImageColorAllocate($image, $arrR[rand(0, 6)], $arrG[rand(0, 6)], $arrB[rand(0, 6)]); $white = ImageColorAllocate($image, 255, 255, 255); $grey = ImageColorAllocate($image, 175, 253, 253); //Make the background black ImageFill($image, 0, 0, $black); $font = 5; $arrSel = array(1, 2, 3, 4); $selectedNum = $arrSel[rand(0, 3)]; ImageString($image, $font, 10, 10, $security_code, $white); //Throw in some lines to make it a little bit harder for any bots to break ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey); if ($selectedNum == 1) { imageline($image, 0, $height / 2, $width, $height / 5, $grey); imageline($image, $width / 2, 0, $width / 3, $height / 5, $grey); imageline($image, $width / 2, 0, $width / 10, $height, $grey); imageline($image, $width / 2, 0, $width / 10, $height / 6, $grey); } if ($selectedNum == 2) { imageline($image, $width / 1, 0, $width / 6, $height, $grey); imageline($image, 0, $height / 5, $width, $height / 8, $grey); imageline($image, 0, $height / 5, $width / 5, $height / 8, $grey); imageline($image, 0, $height / 3, $width, $height, $grey); } if ($selectedNum == 3) { imageline($image, 0, $height, $width, 0, $grey); imageline($image, 0, 0, $height, $height, $grey); imageline($image, $width / 5, 0, $width / 6, $height, $grey); imageline($image, $width / 4, 0, $width / 4, $height, $grey); } //Tell the browser what kind of file is come in header("Content-Type: image/jpeg"); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); }
function GraphNormalize($title, $options = NULL) { $this->options = $options; $this->interval = $this->options['interval'] ? $this->options['interval'] : 10; // TODO: Move these to friendly options $this->image_size = array(600, 400); $this->canvas_offset = array(25, 50, 25, 25); $this->canvas_size = array($this->image_size[0] - ($this->canvas_offset[0] + $this->canvas_offset[2]), $this->image_size[1] - ($this->canvas_offset[1] + $this->canvas_offset[3])); // Actual creation stuff $this->graph = ImageCreate($this->image_size[0], $this->image_size[1]); $this->color['background'] = ImageColorAllocate($this->graph, 0xff, 0xff, 0xff); $this->color['line'] = ImageColorAllocate($this->graph, 0x60, 0x60, 0x60); $this->color['border'] = ImageColorAllocate($this->graph, 0x0, 0x0, 0x0); $this->color['text'] = ImageColorAllocate($this->graph, 0x0, 0x0, 0x0); $this->color['grid'] = ImageColorAllocate($this->graph, 0xc0, 0xc0, 0xc0); $this->color['canvas'] = ImageColorAllocate($this->graph, 0xe0, 0xe0, 0xe0); $this->color['legendbox'] = ImageColorAllocate($this->graph, 0xd0, 0xd0, 0xf0); $this->color['titlebox'] = ImageColorAllocate($this->graph, 0xd0, 0xf0, 0xf0); $this->color['data'] = array(ImageColorAllocate($this->graph, 0xff, 0x0, 0x0), ImageColorAllocate($this->graph, 0x0, 0xcc, 0x0), ImageColorAllocate($this->graph, 0x0, 0x0, 0xff), ImageColorAllocate($this->graph, 0xff, 0xff, 0x0), ImageColorAllocate($this->graph, 0x0, 0xff, 0xff), ImageColorAllocate($this->graph, 0xff, 0x0, 0xff)); $this->font = 'lib/template/default/Vera.ttf'; $this->title = $title; $this->set_count = 0; // Define canvas, so we don't go crazy $this->ca = array($this->canvas_offset[0], $this->canvas_offset[1], $this->canvas_size[0] - $this->canvas_offset[2] - 1, $this->canvas_size[1] - $this->canvas_offset[3] - 1); }
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2 * $outerFrame; $imgH = $h + 2 * $outerFrame; $base_image = imagecreatetruecolor($imgW, $imgH); $col[0] = ImageColorAllocate($base_image, 255, 0, 255); $col[1] = ImageColorAllocate($base_image, 0, 0, 0); imagecolortransparent($base_image, $col[0]); imagealphablending($base_image, true); imagesavealpha($base_image, true); // imagefill($base_image, 0, 0, $col[0]); imagefill($base_image, 0, 0, 0x7fff0000); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); } } } $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); ImageDestroy($base_image); return $target_image; }
function JPGText($str, $fontname, $fontsize, $backcol, $txtcol) { global $layout; Header("Last-Modified: " . gmDate("D, d M Y H:i:s", Time()) . " GMT"); Header("Expires: " . gmDate("D, d M Y H:i:s", Time() - 3601) . " GMT"); Header("Pragma: no-cache"); Header("Cache-control: no-cache"); Header("Content-Type: image/jpeg"); $a = ImageTTFBBox($fontsize, 0, $fontname, $str); $width = $a[2] + 4; $bla = get_maximum_height($fontname, $fontsize); $height = $bla[0] + 3; $bl = $bla[1]; $im = ImageCreate($width, $height); $bgcol = ImageColorAllocate($im, $backcol['red'], $backcol['green'], $backcol['blue']); $fgcol = ImageColorAllocate($im, $txtcol['red'], $txtcol['green'], $txtcol['blue']); if (!function_exists(imagegif)) { imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str); imagejpeg($im, "", 80); } else { ImageColorTransparent($im, $bgcol); imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str); imagegif($im); } ImageDestroy($im); }
function pcs_href_image($src_path) { $strRet = DIR_WS_IMAGES . 'pcs_images/' . basename($src_path) . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH . '_' . MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY . '.jpg'; #This will be the filename of the resized image. if (!file_exists($strRet)) { #Create the file if it does not exist #check to see if source file exists if (!file_exists($src_path)) { return 'error1'; #check to see if source file is readable } elseif (!is_readable($src_path)) { return 'error2'; } #check if gif if (stristr(strtolower($src_path), '.gif')) { $oldImage = ImageCreateFromGif($src_path); } elseif (stristr(strtolower($src_path), '.jpg') || stristr(strtolower($src_path), '.jpeg')) { $oldImage = ImageCreateFromJpeg($src_path); } elseif (stristr(strtolower($src_path), '.png')) { $oldImage = ImageCreateFromPng($src_path); } else { return 'error3'; } #Create the new image if (function_exists("ImageCreateTrueColor")) { $newImage = ImageCreateTrueColor(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT); } else { $newImage = ImageCreate(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT); } $backgroundColor = imagecolorallocate($newImage, 255, 255, 255); imagefill($newImage, 0, 0, $backgroundColor); #calculate the rezised image's dimmensions if (imagesx($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH || imagesy($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) { #Resize image if (imagesx($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH > imagesy($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) { #Width is leading in beeing to large $newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH; $newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / imagesx($oldImage) * imagesy($oldImage); } else { #Height is leading in beeing to large $newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT; $newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / imagesy($oldImage) * imagesx($oldImage); } } else { #Don't rezise image $newWidth = imagesx($oldImage); $newHeight = imagesy($oldImage); } #Copy the old image onto the new image ImageCopyResampled($newImage, $oldImage, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / 2 - $newWidth / 2, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / 2 - $newHeight / 2, 0, 0, $newWidth, $newHeight, imagesx($oldImage), imagesy($oldImage)); imagejpeg($newImage, $strRet, MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY); #save the image imagedestroy($oldImage); #Free Memory imagedestroy($newImage); #Free memory } return $strRet; }
public static function Barcode39($barcode, $width, $height, $quality, $text, $path) { $im = ImageCreate($width, $height) or die("Cannot Initialize new GD image stream"); $White = ImageColorAllocate($im, 255, 255, 255); $Black = ImageColorAllocate($im, 0, 0, 0); //ImageColorTransparent ($im, $White); ImageInterLace($im, 1); $NarrowRatio = 20; $WideRatio = 55; $QuietRatio = 35; $nChars = (strlen($barcode) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio); $Pixels = $width / $nChars; $NarrowBar = (int) (20 * $Pixels); $WideBar = (int) (55 * $Pixels); $QuietBar = (int) (35 * $Pixels); $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($barcode) + 2); if ($NarrowBar == 0 || $NarrowBar == $WideBar || $NarrowBar == $QuietBar || $WideBar == 0 || $WideBar == $QuietBar || $QuietBar == 0) { ImageString($im, 1, 0, 0, "Image is too small!", $Black); OutputImage($im, $format, $quality); exit; } $CurrentBarX = (int) (($width - $ActualWidth) / 2); $Color = $White; $BarcodeFull = "*" . strtoupper($barcode) . "*"; settype($BarcodeFull, "string"); $FontNum = 3; $FontHeight = ImageFontHeight($FontNum); $FontWidth = ImageFontWidth($FontNum); if ($text != 0) { $CenterLoc = (int) (($width - 1) / 2) - (int) ($FontWidth * strlen($BarcodeFull) / 2); ImageString($im, $FontNum, $CenterLoc, $height - $FontHeight, "{$BarcodeFull}", $Black); } else { $FontHeight = -2; } for ($i = 0; $i < strlen($BarcodeFull); $i++) { $StripeCode = self::Code39($BarcodeFull[$i]); for ($n = 0; $n < 9; $n++) { if ($Color == $White) { $Color = $Black; } else { $Color = $White; } switch ($StripeCode[$n]) { case '0': ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color); $CurrentBarX += $NarrowBar; break; case '1': ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color); $CurrentBarX += $WideBar; break; } } $Color = $White; ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color); $CurrentBarX += $QuietBar; } return ImageJPEG($im, $path, $quality); }
function create($varDesc, $varValues) { Header("Content-type: image/png"); $image = ImageCreate($this->imageWidth, $this->imageHeight); $bgcolor = ImageColorAllocate($image, $this->bgR, $this->bgG, $this->bgB); $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); ImageFill($image, 0, 0, $bgcolor); $num = 0; foreach ($varDesc as $v) { $r = rand(0, 255); $g = rand(0, 255); $b = rand(0, 255); $sliceColors[$num] = ImageColorAllocate($image, $r, $g, $b); $num++; } // now $num has the number of elements // draw the box ImageLine($image, 0, 0, $this->imageWidth - 1, 0, $black); ImageLine($image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $black); ImageLine($image, $this->imageWidth - 1, $this->imageHeight - 1, 0, $this->imageHeight - 1, $black); ImageLine($image, 0, $this->imageHeight - 1, 0, 0, $black); $total = 0; for ($x = 0; $x < $num; $x++) { $total += $varValues[$x]; } // convert each slice into corresponding percentage of 360-degree circle for ($x = 0; $x < $num; $x++) { $angles[$x] = $varValues[$x] / $total * 360; } for ($x = 0; $x < $num; $x++) { // calculate and draw arc corresponding to each slice ImageArc($image, $this->imageWidth / 4, $this->imageHeight / 2, $this->imageWidth / 3, $this->imageHeight / 3, $angle, $angle + $angles[$x], $sliceColors[$x]); $angle = $angle + $angles[$x]; $x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos($angle * pi() / 180) / 2); $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin($angle * pi() / 180) / 2); // demarcate slice with another line ImageLine($image, $this->imageWidth / 4, $this->imageHeight / 2, $x1, $y1, $sliceColors[$x]); } // fill in the arcs $angle = 0; for ($x = 0; $x < $num; $x++) { $x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos(($angle + $angles[$x] / 2) * pi() / 180) / 4); $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin(($angle + $angles[$x] / 2) * pi() / 180) / 4); ImageFill($image, $x1, $y1, $sliceColors[$x]); $angle = $angle + $angles[$x]; } // put the desc strings ImageString($image, 5, $this->imageWidth / 2, 60, "Legend", $black); for ($x = 0; $x < $num; $x++) { $fl = sprintf("%.2f", $varValues[$x] * 100 / $total); $str = $varDesc[$x] . " (" . $fl . "%)"; ImageString($image, 3, $this->imageWidth / 2, ($x + 5) * 20, $str, $sliceColors[$x]); } // put the title ImageString($image, 5, 20, 20, $this->title, $black); ImagePng($image); ImageDestroy($image); }
function ImageResize($srcFile, $toW, $toH, $toFile = "") { if ($toFile == "") { $toFile = $srcFile; } $info = ""; $data = GetImageSize($srcFile, $info); switch ($data[2]) { case 1: if (!function_exists("imagecreatefromgif")) { echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>"; exit; } $im = ImageCreateFromGIF($srcFile); break; case 2: if (!function_exists("imagecreatefromjpeg")) { echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>"; exit; } $im = ImageCreateFromJpeg($srcFile); break; case 3: $im = ImageCreateFromPNG($srcFile); break; } $srcW = ImageSX($im); $srcH = ImageSY($im); $toWH = $toW / $toH; $srcWH = $srcW / $srcH; if ($toWH <= $srcWH) { $ftoW = $toW; $ftoH = $ftoW * ($srcH / $srcW); } else { $ftoH = $toH; $ftoW = $ftoH * ($srcW / $srcH); } if ($srcW > $toW || $srcH > $toH) { if (function_exists("imagecreatetruecolor")) { @($ni = ImageCreateTrueColor($ftoW, $ftoH)); if ($ni) { ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); } else { $ni = ImageCreate($ftoW, $ftoH); ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); } } else { $ni = ImageCreate($ftoW, $ftoH); ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); } if (function_exists('imagejpeg')) { ImageJpeg($ni, $toFile); } else { ImagePNG($ni, $toFile); } ImageDestroy($ni); } ImageDestroy($im); }
function avg_percent_fit_iskill($db_object, $common, $image, $user_id) { $user_table = $common->prefix_table("user_table"); $model_factors_1 = $common->prefix_table("model_factors_1"); $model_percent_fit = $common->prefix_table("models_percent_fit"); $family_position = $common->prefix_table("family_position"); $career_goals = $common->prefix_table("career_goals"); $sql = "select position from {$user_table} where user_id='{$user_id}'"; $sql_res = $db_object->get_a_line($sql); $pos_id = $sql_res[position]; $user_pos = $common->get_chain_below($pos_id, $db_object, $twodarr); $count = 0; if (count($user_pos) == 0) { $heads = array(array("No employee", 3, "c"), array("under this admin", 3, "c")); $image = ImageCreate(150, 150); $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); ImageString($image, $heads[0][1], 10, 0, $heads[0][0], $black); ImageString($image, $heads[1][1], 10, 15, $heads[1][0], $black); //ImageString($image,3,50,50,'heading',16); ImagePng($image); } for ($i = 0; $i < count($user_pos); $i++) { $pos = $user_pos[$i]; $sql = "select user_id from {$user_table} where position='{$pos}'"; $user_res = $db_object->get_a_line($sql); $user = $user_res[user_id]; $sql = "select onelevel_up from {$career_goals} where user_id='{$user}'"; $fly_res = $db_object->get_single_column($sql); if (count($fly_res) > 0) { $family_ids = @implode(",", $fly_res); $fly = "(" . $family_ids . ")"; $sql = "select model_id from {$model_factors_1} where family in {$fly}"; $model_arr = $db_object->get_single_column($sql); if (count($model_arr) > 0) { $model_ids = @implode(",", $model_arr); $models = "(" . $model_ids . ")"; $sql = "select avg(percent_fit) as percent from {$model_percent_fit} where model_id in {$models} \n\t\t\t\t\t\n\t\t\t\t\tand user_id='{$user}'"; $percent_arr = $db_object->get_a_line($sql); $total_percent += $percent_arr[0]; $count++; } } } if ($count >= 1) { $percent = $total_percent / $count; } else { $percent = 0; } $total = 100; $heads = array(array("One Level Up Fit", 3, "c")); $array = array($percent, $total); $vals = $image->return_Array($array); $image->init(150, 150, $vals); $image->draw_heading($heads); $image->set_legend_percent(); $image->display($filename); }
function resampleImage() { if (function_exists('ImageCreateTrueColor')) { $this->img["des"] = ImageCreateTrueColor($this->img["width_thumb"], $this->img["height_thumb"]); } else { $this->img["des"] = ImageCreate($this->img["width_thumb"], $this->img["height_thumb"]); } imagecopyresampled($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"], $this->img["height_thumb"], $this->img["width"], $this->img["height"]); }
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2 * $outerFrame; $imgH = $h + 2 * $outerFrame; $base_image = ImageCreate($imgW, $imgH); $col[0] = ImageColorAllocate($base_image, 255, 255, 255); $col[1] = ImageColorAllocate($base_image, 0, 0, 0); imagefill($base_image, 0, 0, $col[0]); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); } } } //$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); //ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); //Get Desired size of image. //Insert the following code to generate desired size QR Code //Example:----- (Note: this should be written in the file where we are going to generate the QR Code) //------define('IMAGE_WIDTH',160); //------define('IMAGE_HEIGHT',160); //------QRcode::png(); $targetW = defined('IMAGE_WIDTH') ? IMAGE_WIDTH : $imgW * $pixelPerPoint; $targetH = defined('IMAGE_HEIGHT') ? IMAGE_HEIGHT : $imgH * $pixelPerPoint; $target_image = ImageCreate($targetW, $targetH); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $targetW, $targetH, $imgW, $imgH); //Transparent Background QR code ImageColorTransparent($target_image, $col[0]); ImageDestroy($base_image); return $target_image; }
function mkimage($data) { $data_array = explode("\n", $data); $c = count($data_array) - 1; $image_size = $c; $output_size = ($c + $this->quiet_zone * 2) * $this->module_size; $img = ImageCreate($image_size, $image_size); $white = ImageColorAllocate($img, 255, 255, 255); $black = ImageColorAllocate($img, 0, 0, 0); $im = ImageCreate($output_size, $output_size); $white2 = ImageColorAllocate($im, 255, 255, 255); ImageFill($im, 0, 0, $white2); $y = 0; foreach ($data_array as $row) { $x = 0; while ($x < $image_size) { if (substr($row, $x, 1) == "1") { ImageSetPixel($img, $x, $y, $black); } $x++; } $y++; } $quiet_zone_offset = $this->quiet_zone * $this->module_size; $image_width = $image_size * $this->module_size; ImageCopyResized($im, $img, $quiet_zone_offset, $quiet_zone_offset, 0, 0, $image_width, $image_width, $image_size, $image_size); return $im; }