public function createImage($text = '', $fontSize = 5) { // GD's built-in fonts are numbered from 1 - 5 $font_size = $fontSize; // Calculate the appropriate image size $image_height = intval(imageFontHeight($font_size) * 2); $image_width = intval(strlen($text) * imageFontWidth($font_size) * 1.3); // Create the image $image = imageCreate($image_width, $image_height); // Create the colors to use in the image // gray background $back_color = imageColorAllocate($image, 216, 216, 216); // blue text $text_color = imageColorAllocate($image, 0, 0, 255); // black border $rect_color = imageColorAllocate($image, 0, 0, 0); // Figure out where to draw the text // (Centered horizontally and vertically $x = ($image_width - imageFontWidth($font_size) * strlen($text)) / 2; $y = ($image_height - imageFontHeight($font_size)) / 2; // Draw the text imageString($image, $font_size, $x, $y, $text, $text_color); // Draw a black border imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color); // Send the image to the browser header('Content-Type: image/png'); imagePNG($image); imageDestroy($image); }
function create($text) { $img = imagecreatefrompng("skins/icon.png"); $black = imageColorAllocate($img, 0, 0, 0); $white = imageColorAllocate($img, 255, 255, 255); imageString($img, 5, 20, 3, $text, $white); imagePNG($img); }
public function creat_images($num) { $type = 2; header("Content-type: image/PNG"); // 產生種子, 作圖形干擾用 srand((double) microtime() * 10000000000); // 產生圖檔, 及定義顏色 $img_x = 120; $img_y = 28; $im = imageCreate($img_x, $img_y); //ImageColorAllocate 分配圖形的顏色 $back = ImageColorAllocate($im, rand(200, 255), rand(200, 255), rand(200, 255)); $authText = $this->num2adb($num); imageFill($im, 0, 0, $back); // imageString($im, 5, rand(0,55), rand(0,40), $authText, $font); $str_x = 0; $str_y = 0; for ($i = 0; $i < strlen($authText); $i++) { $str_x += rand(10, 20); $str_y = rand(0, $img_y / 2); $font = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100)); imageString($im, 5, $str_x, $str_y, $authText[$i], $font); } // 插入圖形干擾點共 50 點, 可插入更多, 但可能會使圖形太過混雜 for ($i = 0; $i < rand(50, 200); $i++) { $point = ImageColorAllocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imagesetpixel($im, rand(0, $img_x), rand(0, $img_y), $point); } for ($i = 1; $i <= rand(2, 5); $i++) { $point = ImageColorAllocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imageline($im, rand(0, $img_x), rand(0, $img_y), rand(0, $img_x), rand(0, $img_y), $point); } // 定義圖檔類型並輸入, 最後刪除記憶體 if ($type == 1) { ob_start(); ImagePNG($im); $output = ob_get_contents(); ob_end_clean(); echo base64_encode($output); } else { ImagePNG($im); } ImageDestroy($im); }
$labelH = 10; $wnd = $wnds_max; /* start with max wind speed */ $dwnd = ($wnds_max - $wnds_min) / $tics; $flag = false; /* use this to only display every other tic label */ for ($i = $dy, $ii = 0; $i <= $gyb + $dy; $i += $gyb / $tics) { /* y axis2 tics */ imageLine($im, $dx + $gxb - $ticW, $i, $dx + $gxb + $ticW, $i, $black); /* y axis2 horizontal graph lines */ if ($i + 1 < $gyb + $dy) { imageLine($im, $dx, $i, $dx + $gxb - $ticW, $i, $ltGrey); } /* y axis2 labels */ // if($flag=!$flag){ imageString($im, 5, $dx + $gxb + 2 * $ticW, $i - $labelH, sprintf("%3.1f", $wnd), $blue); //} $wnd -= $dwnd; if ($wnd < 0) { $wnd = -$wnd; } } /* draw the wind direction graph */ $scale = $gyb / 360; /* wind direction can only go from 0 to 360 degrees */ for ($i = 0; $i + 1 < $row_count; $i++) { $x1 = $i * $gxb / $row_count + $dx; $y1 = $gyb + $dy - $windd[$i] * $scale; $x2 = ($i + 1) * $gxb / $row_count + $dx; $y2 = $gyb + $dy - $windd[$i + 1] * $scale; imageLine($im, $x1, $y1, $x2, $y2, $red);
/** * Appends information about the source image to the thumbnail. * * @param string $thumbnail * @return string */ protected function appendSourceInfo($thumbnail) { if (!function_exists('imageCreateFromString') || !function_exists('imageCreateTrueColor')) { return $thumbnail; } $imageSrc = imageCreateFromString($thumbnail); // get image size $width = imageSX($imageSrc); $height = imageSY($imageSrc); // increase height $heightDst = $height + self::$sourceInfoLineHeight * 2; // create new image $imageDst = imageCreateTrueColor($width, $heightDst); imageAlphaBlending($imageDst, false); // set background color $background = imageColorAllocate($imageDst, 102, 102, 102); imageFill($imageDst, 0, 0, $background); // copy image imageCopy($imageDst, $imageSrc, 0, 0, 0, 0, $width, $height); imageSaveAlpha($imageDst, true); // get font size $font = 2; $fontWidth = imageFontWidth($font); $fontHeight = imageFontHeight($font); $fontColor = imageColorAllocate($imageDst, 255, 255, 255); // write source info $line1 = $this->sourceName; // imageString supports only ISO-8859-1 encoded strings if (CHARSET != 'ISO-8859-1') { $line1 = StringUtil::convertEncoding(CHARSET, 'ISO-8859-1', $line1); } // truncate text if necessary $maxChars = floor($width / $fontWidth); if (strlen($line1) > $maxChars) { $line1 = $this->truncateSourceName($line1, $maxChars); } $line2 = $this->sourceWidth . 'x' . $this->sourceHeight . ' ' . FileUtil::formatFilesize($this->sourceSize); // write line 1 // calculate text position $textX = 0; $textY = 0; if ($fontHeight < self::$sourceInfoLineHeight) { $textY = intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2)); } if (strlen($line1) * $fontWidth < $width) { $textX = intval(round(($width - strlen($line1) * $fontWidth) / 2)); } imageString($imageDst, $font, $textX, $height + $textY, $line1, $fontColor); // write line 2 // calculate text position $textX = 0; $textY = 0; if ($fontHeight < self::$sourceInfoLineHeight) { $textY = self::$sourceInfoLineHeight + intval(round((self::$sourceInfoLineHeight - $fontHeight) / 2)); } if (strlen($line2) * $fontWidth < $width) { $textX = intval(round(($width - strlen($line2) * $fontWidth) / 2)); } imageString($imageDst, $font, $textX, $height + $textY, $line2, $fontColor); // output image ob_start(); if ($this->imageType == 1 && function_exists('imageGIF')) { @imageGIF($imageDst); $this->mimeType = 'image/gif'; } else { if (($this->imageType == 1 || $this->imageType == 3) && function_exists('imagePNG')) { @imagePNG($imageDst); $this->mimeType = 'image/png'; } else { if (function_exists('imageJPEG')) { @imageJPEG($imageDst, null, 90); $this->mimeType = 'image/jpeg'; } else { return false; } } } @imageDestroy($imageDst); $thumbnail = ob_get_contents(); ob_end_clean(); return $thumbnail; }
function codes_f() { $x_size = 76; $y_size = 23; if (!defined("SYS_VCODE_VAR")) { define("SYS_VCODE_VAR", "phpok_login_chk"); } $aimg = imagecreate($x_size, $y_size); $back = imagecolorallocate($aimg, 255, 255, 255); $border = imagecolorallocate($aimg, 0, 0, 0); imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back); $txt = "0123456789"; $txtlen = strlen($txt); $thetxt = ""; for ($i = 0; $i < 4; $i++) { $randnum = mt_rand(0, $txtlen - 1); $randang = mt_rand(-10, 10); //文字旋转角度 $rndtxt = substr($txt, $randnum, 1); $thetxt .= $rndtxt; $rndx = mt_rand(1, 5); $rndy = mt_rand(1, 4); $colornum1 = $rndx * $rndx * $randnum % 255; $colornum2 = $rndy * $rndy * $randnum % 255; $colornum3 = $rndx * $rndy * $randnum % 255; $newcolor = imagecolorallocate($aimg, $colornum1, $colornum2, $colornum3); imageString($aimg, 3, $rndx + $i * 21, 5 + $rndy, $rndtxt, $newcolor); } unset($txt); $thetxt = strtolower($thetxt); $_SESSION[SYS_VCODE_VAR] = md5($thetxt); #[写入session中] @session_write_close(); #[关闭session写入] imagerectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $border); $newcolor = ""; $newx = ""; $newy = ""; $pxsum = 30; //干扰像素个数 for ($i = 0; $i < $pxsum; $i++) { $newcolor = imagecolorallocate($aimg, mt_rand(0, 254), mt_rand(0, 254), mt_rand(0, 254)); imagesetpixel($aimg, mt_rand(0, $x_size - 1), mt_rand(0, $y_size - 1), $newcolor); } header("Pragma:no-cache"); header("Cache-control:no-cache"); header("Content-type: image/png"); imagepng($aimg); imagedestroy($aimg); exit; }
<?php // GD's built-in fonts are numbered from 1 - 5 $font_size = 5; // Calculate the appropriate image size $image_height = intval(imageFontHeight($font_size) * 2); $image_width = intval(strlen($_GET['text']) * imageFontWidth($font_size) * 1.3); // Create the image $image = imageCreate($image_width, $image_height); // Create the colors to use in the image // gray background $back_color = imageColorAllocate($image, 216, 216, 216); // blue text $text_color = imageColorAllocate($image, 0, 0, 255); // black border $rect_color = imageColorAllocate($image, 0, 0, 0); // Figure out where to draw the text // (Centered horizontally and vertically $x = ($image_width - imageFontWidth($font_size) * strlen($_GET['text'])) / 2; $y = ($image_height - imageFontHeight($font_size)) / 2; // Draw the text imageString($image, $font_size, $x, $y, $_GET['text'], $text_color); // Draw a black border imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color); // Send the image to the browser header('Content-Type: image/png'); imagePNG($image); imageDestroy($image);
/** * Function: drawFixedTextLine * * Draws the given fixed text line. */ function drawFixedTextLine($text, $font, $left, $top, $color, $horizontal = true) { if ($horizontal) { imageString($this->image, $font, $left, $top, $text, $color); } else { imageStringUp($this->image, $font, $left, $top, $text, $color); } }
function skyview($im, $sz, $C) { $a = 90; $a = $sz * 0.95 * ($a / 180); imageFilledArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['mdgray'], 0); imageArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['black']); $x = $sz / 2 - 16; $y = $sz / 2 - $a; imageString($im, 2, $x, $y, "0", $C['ltgray']); $a = 85; $a = $sz * 0.95 * ($a / 180); imageFilledArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['white'], 0); imageArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['ltgray']); imageString($im, 1, $sz / 2 - 6, $sz + $a, '5', $C['black']); $x = $sz / 2 - 16; $y = $sz / 2 - $a; imageString($im, 2, $x, $y, "5", $C['ltgray']); skygrid($im, $sz, $C); $x = $sz / 2 - 16; $y = $sz / 2 - 8; /* imageString($im, 2, $x, $y, "90", $C['ltgray']); */ imageString($im, 4, $sz / 2 + 4, 2, 'N', $C['black']); imageString($im, 4, $sz / 2 + 4, $sz - 16, 'S', $C['black']); imageString($im, 4, 4, $sz / 2 + 4, 'E', $C['black']); imageString($im, 4, $sz - 10, $sz / 2 + 4, 'W', $C['black']); }
/** * Creates error image based on gfx/notfound_thumb.png * Requires GD lib enabled, otherwise it will exit with the three textstrings outputted as text. * Outputs the image stream to browser and exits! * * @param string $l1 Text line 1 * @param string $l2 Text line 2 * @param string $l3 Text line 3 * @return void * @todo Define visibility */ public function errorGif($l1, $l2, $l3) { if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $l1 . ' ' . $l2 . ' ' . $l3, 1270853954); } // Creates the basis for the error image if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { header('Content-type: image/png'); $im = imagecreatefrompng(PATH_typo3 . 'gfx/notfound_thumb.png'); } else { header('Content-type: image/gif'); $im = imagecreatefromgif(PATH_typo3 . 'gfx/notfound_thumb.gif'); } // Sets background color and print color. $white = imageColorAllocate($im, 255, 255, 255); $black = imageColorAllocate($im, 0, 0, 0); // Prints the text strings with the build-in font functions of GD $x = 0; $font = 0; if ($l1) { imagefilledrectangle($im, $x, 9, 56, 16, $white); imageString($im, $font, $x, 9, $l1, $black); } if ($l2) { imagefilledrectangle($im, $x, 19, 56, 26, $white); imageString($im, $font, $x, 19, $l2, $black); } if ($l3) { imagefilledrectangle($im, $x, 29, 56, 36, $white); imageString($im, $font, $x, 29, substr($l3, -14), $black); } // Outputting the image stream and exit if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { imagePng($im); } else { imageGif($im); } imagedestroy($im); die; }
/** * Controller */ public function process() { if (\Core\Route\Controller::$isApi) { header('Content-type: application/json'); echo json_encode(['error' => 404, 'uri' => $_SERVER['REQUEST_URI']]); exit; } $aRequests = Phpfox_Request::instance()->getRequests(); if ($sPlugin = Phpfox_Plugin::get('error.component_controller_notfound_1')) { eval($sPlugin); if (isset($mReturnPlugin)) { return $mReturnPlugin; } } $aNewRequests = array(); $iCnt = 0; foreach ($aRequests as $sKey => $sValue) { if (!preg_match('/req[0-9]/', $sKey)) { $aNewRequests[$sKey] = $sValue; continue; } if ($sValue == 'public') { continue; } $iCnt++; $aNewRequests['req' . $iCnt] = $sValue; } if (isset($aNewRequests['req1'])) { if ($aNewRequests['req1'] == 'gallery') { $aNewRequests['req1'] = 'photo'; } elseif ($aNewRequests['req1'] == 'browse') { $aNewRequests['req1'] = 'user'; } elseif ($aNewRequests['req1'] == 'groups') { $aNewRequests['req1'] = 'group'; } elseif ($aNewRequests['req1'] == 'videos') { $aNewRequests['req1'] = 'video'; } elseif ($aNewRequests['req1'] == 'listing') { $aNewRequests['req1'] = 'marketplace'; } } if (isset($aNewRequests['req1']) && Phpfox::isModule($aNewRequests['req1']) && Phpfox::hasCallback($aNewRequests['req1'], 'legacyRedirect')) { $sRedirect = Phpfox::callback($aNewRequests['req1'] . '.legacyRedirect', $aNewRequests); } if (isset($sRedirect) && $sRedirect !== false && !defined('PHPFOX_IS_FORCED_404')) { header('HTTP/1.1 301 Moved Permanently'); if (is_array($sRedirect)) { $this->url()->send($sRedirect[0], $sRedirect[1]); } $this->url()->send($sRedirect); } if (Phpfox::getParam(array('balancer', 'enabled'))) { $sDo = $this->request()->get(PHPFOX_GET_METHOD); if (preg_match('/\\/file\\/css\\/(.*)_(.*)/i', $sDo, $aMatches)) { $sContent = file_get_contents(Phpfox::getLib('server')->getServerUrl($aMatches[1]) . ltrim($sDo, '/')); $hFile = fopen(PHPFOX_DIR . ltrim($sDo, '/'), 'w+'); fwrite($hFile, $sContent); fclose($hFile); header("Content-type: text/css"); echo $sContent; exit; } } header("HTTP/1.0 404 Not Found"); $sUrl = isset($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : ''; $sCurrentUrl = $_SERVER['REQUEST_URI']; $aParts = explode('?', $sCurrentUrl); $sNewUrl = $aParts[0]; if (substr($sNewUrl, -3) == '.js') { exit('JavaScript file not found.'); } elseif (substr($sNewUrl, -4) == '.css') { exit('CSS file not found.'); } if ($sUrl) { // If its an image lets create a small "not found" image if (substr($sUrl, -4) == '.gif' || substr($sUrl, -4) == '.png' || substr($sUrl, -4) == '.jpg' || substr($sUrl, -5) == '.jpeg') { // Log any missing images if the setting is enabled (Mostly used when developing new themes) if (Phpfox::getParam('core.log_missing_images')) { if ($hFile = @fopen(PHPFOX_DIR . 'file/log/phpfox_missing_images.log', 'a+')) { $sData = $sUrl . (isset($_SERVER['HTTP_REFERER']) ? " ({$_SERVER['HTTP_REFERER']})" : ""); fwrite($hFile, $sUrl . "\n"); fclose($hFile); } } $sText = 'Not Found!'; $nW = 100; $nH = 30; $nLeft = 5; $nTop = 5; $hImg = imageCreate($nW, $nH); $nBgColor = imageColorAllocate($hImg, 0, 0, 0); $nTxtColor = imageColorAllocate($hImg, 255, 255, 255); imageString($hImg, 5, $nLeft, $nTop, $sText, $nTxtColor); ob_clean(); header('Content-Type: image/jpeg'); imagejpeg($hImg); exit; } } $this->template()->errorClearAll(); $this->template()->setTitle('Page Not Found'); $this->template()->setBreadcrumb('Page Not Found'); $this->template()->assign('aFilterMenus', array()); }
/** * Draws text on the image * @param Point $leftTop Point of the upper left corner * @param Color $color * @param string $text * @return null */ public function drawText(Point $leftTop, Color $color, $text) { $color = $this->allocateColor($color); imageString($this->resource, 2, $leftTop->getX(), $leftTop->getY(), $text, $color); }
<?php require_once 'inc.config.php'; // $code = mysql_result(mysql_query("SELECT code FROM $TABLE[logincodes] WHERE id='".$_GET['cid']."';"),0,'code'); $code = " " . rand(11111, 99999); $_SESSION['ps_logincode'] = $code; $plaatje = ImageCreateTrueColor(84, 30); $color_border = ImageColorAllocate($plaatje, 0, 0, 0); $color_bg = ImageColorAllocate($plaatje, 255, 255, 255); $color_text = ImageColorAllocate($plaatje, 0, 0, 0); ImageFilledRectangle($plaatje, 0, 0, 84, 30, $color_border); ImageFilledRectangle($plaatje, 1, 1, 82, 28, $color_bg); for ($i = 0; $i < strlen($code); $i++) { $fontnum = rand(2, 5); $color_text = ImageColorAllocate($plaatje, rand(50, 205), rand(50, 205), rand(50, 205)); $x = 4 + 10 * $i; $y = rand(0, 12); imageString($plaatje, $fontnum, $x, $y, $code[$i], $color_text); } // Twee lijnen voor de onduidelijkheid ImageLine($plaatje, rand(0, 84), rand(0, 30), rand(0, 84), rand(0, 30), $color_border); ImageLine($plaatje, rand(0, 84), rand(0, 30), rand(0, 84), rand(0, 30), $color_border); Header("Content-type: image/jpeg"); ImagePNG($plaatje); ImageDestroy($plaatje);
if ($count > $max2) { $max2 = $count; } if ($count > 0) { imageLine($image, $i, $j * $va + $vs - $count, $i, $j * $va + $vs, $green); } $j++; } //while $i++; $i++; } //for $mo imageLine($image, $i, $vs - $va * 2, $i, $diagramHeight - 1, $black); } //for $y $j = 0; foreach ($cats as $cat) { imageFilledRectangle($image, 1, $j * $va + $vs - ($va - 1), $hs - 1, $j * $va + $vs - ($va - 11), $colorBackgr); imageString($image, 3, 2, $j * $va + $vs - $va, "{$cats[$j]}", $black); $j++; } pg_close($dbconn); echo "max records/month= {$max} max2 pixels= {$max2}<br>\n"; //create an interlaced image for better loadingin the browser imageInterlace($image, 1); //mark background coloras being transparent //imageColorTransparent($image,$colorBackgr); imagePNG($image, "{$secdir}/hec.png"); //exec ("chmod 777 $secdir/temp.png"); echo "<br><IMG SRC=\"hec.png\">\n";
/** * 直接顯示圖片 * * 詳細說明 * @形參 字元串 $ImageType 設定顯示圖片的格式 * 10進制數字 $ImageWidth 設定顯示圖片的高度 * 10進制數字 $ImageHeight 設定顯示圖片的寬度 * @開始 1.0 * @最後修改 1.0 * @瀏覽 公開 * @返回值 無 * @throws */ function Show($ImageType = "", $ImageWidth = "", $ImageHeight = "") { global $UseSession; global $_SessionNum; global $CodeLength; global $CodeWithChar; global $ImageType; global $ImageWidth; global $ImageHeight; global $AuthResult; global $FontColor; global $BGColor; global $Transparent; global $NoiseBG; global $NoiseChar; global $TotalNoiseChar; global $JpegQuality; // 生成驗證碼 if ($CodeWithChar) { for ($i = 0; $i < $CodeLength; $i++) { $AuthResult .= dechex(rand(1, 15)); } } else { for ($i = 0; $i < $CodeLength; $i++) { $AuthResult .= rand(1, 9); } } // 檢查有沒有設定圖片的輸出格式,如果沒有,則使用類庫的預設值作為最終結果。 if ($ImageType == "") { $ImageType = $ImageType; } // 檢查有沒有設定圖片的輸出寬度,如果沒有,則使用類庫的預設值作為最終結果。 if ($ImageWidth == "") { $ImageWidth = $ImageWidth; } // 檢查有沒有設定圖片的輸出高度,如果沒有,則使用類庫的預設值作為最終結果。 if ($ImageHeight == "") { $ImageHeight = $ImageHeight; } // 建立圖片流 $im = imagecreate($ImageWidth, $ImageHeight); // 取得背景色 list($bgR, $bgG, $bgB) = $BGColor; // 設定背景色 $background_color = imagecolorallocate($im, $bgR, $bgG, $bgB); // 取得文字顏色 list($fgR, $fgG, $fgB) = $FontColor; // 設定字型顏色 $font_color = imagecolorallocate($im, $fgR, $fgG, $fgB); // 檢查是否需要將背景色透明 if ($Transparent) { ImageColorTransparent($im, $background_color); } if ($NoiseBG) { // ImageRectangle($im, 0, 0, $ImageHeight - 1, $ImageWidth - 1, $background_color);//先成一黑色的矩形把圖片包圍 //下面該生成雪花背景了,其實就是在圖片上生成一些符號 for ($i = 1; $i <= $TotalNoiseChar; $i++) { imageString($im, 1, mt_rand(1, $ImageWidth), mt_rand(1, $ImageHeight), $NoiseChar, imageColorAllocate($im, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255))); } } // 為了區別於背景,這裡的顏色不超過200,上面的不小於200 for ($i = 0; $i < strlen($AuthResult); $i++) { //mt_rand(3,5) //imageString( $im, mt_rand(3,5), $i*$ImageWidth/strlen( $AuthResult )+mt_rand(1,5), mt_rand(1, $ImageHeight/2), $AuthResult[$i], imageColorAllocate( $im, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200) ) ); $tt = imageColorAllocate($im, mt_rand(150, 255), mt_rand(150, 255), mt_rand(100, 255)); //字型顏色設定 ImageTTFText($im, 18, mt_rand(-45, 45), 12 + $i * $ImageWidth / strlen($AuthResult) + mt_rand(1, 5), $ImageHeight * 5 / 7, $tt, "photo/DFFN_Y7.TTC", $AuthResult[$i]); } // 檢查輸出格式 if ($ImageType == "PNG") { header("Content-type: image/png"); imagepng($im); } // 檢查輸出格式 if ($ImageType == "JPEG") { header("Content-type: image/jpeg"); imagejpeg($im, null, $JpegQuality); } // 釋放圖片流 imagedestroy($im); }
function makemap($only_premap = false, $dir = '', $gridid, $return = false, $results = '', $onlyarea = false) { global $gridsizes, $iformat, $CONFIG, $dbprefix, $designpath; @ini_set("memory_limit", "64M"); if (!$gridid) { return; } if (!($gdata = DB_query("SELECT * FROM " . $dbprefix . "grids WHERE gridid='" . (int) $gridid . "'", '*'))) { return; } if (!($data = DB_array("SELECT * FROM " . $dbprefix . "user WHERE gridid='" . (int) $gridid . "'", '*'))) { $data = array(); } if ($gdata['reserve_pixel']) { $only_premap = false; } $gdata['transparency'] = (int) $gdata['transparency'] > 0 ? 100 - $gdata['transparency'] : 100; $gdata['transparency_grey'] = (int) $gdata['transparency_grey'] > 0 ? 100 - $gdata['transparency_grey'] : 100; $BLOCKSIZE_X = $gdata['blocksize_x']; $BLOCKSIZE_Y = $gdata['blocksize_y']; $width = $gdata['grid_type'] ? $gridsizes[$gdata['grid_type']]['x'] : (int) ($gdata['x'] * $BLOCKSIZE_X); $height = $gdata['grid_type'] ? $gridsizes[$gdata['grid_type']]['y'] : (int) ($gdata['y'] * $BLOCKSIZE_Y); $x_plus = $gridsizes[$gdata['grid_type']]['x+']; $y_plus = $gridsizes[$gdata['grid_type']]['y+']; if (!$onlyarea) { if ((int) $gdata['grid_type']) { $grid_template = $dir . 'incs/grid_banner/' . (int) $gdata['grid_type'] . '.png'; $grid_template_premap = @file_exists($dir . 'incs/grid_banner/premap_' . (int) $gdata['grid_type'] . '.png') ? $dir . 'incs/grid_banner/premap_' . (int) $gdata['grid_type'] . '.png' : $grid_template; } else { $grid_template = $dir . 'incs/grid_templates/' . html_entity_decode(stripslashes($gdata['grid_template'])); $grid_template_premap = @file_exists($dir . 'incs/grid_templates/premap_' . html_entity_decode(stripslashes($gdata['grid_template']))) ? $dir . 'incs/grid_templates/premap_' . html_entity_decode(stripslashes($gdata['grid_template'])) : $grid_template; } if (!($checkextension = @getimagesize($grid_template))) { return; } $grid_template_ext = strtolower($checkextension[2]); if (!(int) $gdata['grid_type'] && stristr($gdata['grid_template'], '_block_')) { $grid_create_from_block = true; } if (!$only_premap) { if (!($dest = @imagecreatetruecolor($width, $height))) { $dest = imagecreate($width, $height); } if ($grid_template_ext == 3) { $dest_blank = imagecreatefrompng($grid_template); } elseif ($grid_template_ext == 2) { $dest_blank = imagecreatefromjpeg($grid_template); } elseif ($grid_template_ext == 1) { $dest_blank = imagecreatefromgif($grid_template); } if ($grid_create_from_block) { for ($i = 0; $i < $gdata['y']; $i++) { for ($j = 0; $j < $gdata['x']; $j++) { imagecopyresized($dest, $dest_blank, $j * $BLOCKSIZE_X, $i * $BLOCKSIZE_Y, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $checkextension[0], $checkextension[1]); } } } else { imagecopy($dest, $dest_blank, 0, 0, 0, 0, $width, $height); } imagedestroy($dest_blank); } if (!($dest_premap = @imagecreatetruecolor($width, $height))) { $dest_premap = imagecreate($width, $height); } if ($grid_template_ext == 3) { $dest_premap_blank = imagecreatefrompng($grid_template_premap); } elseif ($grid_template_ext == 2) { $dest_premap_blank = imagecreatefromjpeg($grid_template_premap); } elseif ($grid_template_ext == 1) { $dest_premap_blank = imagecreatefromgif($grid_template_premap); } if ($grid_create_from_block) { for ($i = 0; $i < $gdata['y']; $i++) { for ($j = 0; $j < $gdata['x']; $j++) { imagecopyresized($dest_premap, $dest_premap_blank, $j * $BLOCKSIZE_X, $i * $BLOCKSIZE_Y, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $checkextension[0], $checkextension[1]); } } } else { imagecopy($dest_premap, $dest_premap_blank, 0, 0, 0, 0, $width, $height); } imagedestroy($dest_premap_blank); $src_reserved = imagecreatetruecolor($BLOCKSIZE_X, $BLOCKSIZE_Y); if (!empty($gdata['reserve_bgcolor'])) { $rgb = hex2rgb($gdata['reserve_bgcolor']); imagefill($src_reserved, 0, 0, ImageColorAllocate($src_reserved, $rgb[0], $rgb[1], $rgb[2])); } else { $src_res = imagecreatefrompng($dir . $designpath . 'reserved_pixel.png'); $reserved_x = imagesx($src_res); $reserved_y = imagesy($src_res); if ($reserved_x != $BLOCKSIZE_X || $reserved_y != $BLOCKSIZE_Y) { if (function_exists("imagecopyresampled")) { imagecopyresampled($src_reserved, $src_res, 0, 0, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $reserved_x, $reserved_y); } else { imagecopyresized($src_reserved, $src_res, 0, 0, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $reserved_x, $reserved_y); } } imagedestroy($src_res); } $imagemap = array(); if ($gdata['grid_type']) { $imagemap[] = '<area shape="rect" coords="' . $gridsizes[$gdata['grid_type']]['x1'] . ',' . $gridsizes[$gdata['grid_type']]['y1'] . ',' . $gridsizes[$gdata['grid_type']]['x2'] . ',' . $gridsizes[$gdata['grid_type']]['y2'] . '" href="' . $CONFIG['scriptpath'] . '/getp.php?gr=' . $gridid . '&pa=' . $gdata['page_id'] . '" target="_blank" />'; } } while (list(, $d) = each($data)) { if (is_array($results)) { if (!in_array($d['userid'], $results)) { $gdata['transparency'] = 8; $nomap = true; } else { $gdata['transparency'] = 100; $nomap = false; } $gdata['animated'] = $gdata['hoverimage'] = false; } unset($top, $left, $tops, $lefts, $f_hidden, $koordinaten, $start, $x, $y, $imap); $f_hidden = explode(',', $d['felder']); sort($f_hidden); while (list(, $v) = each($f_hidden)) { $tops[] = (int) (($v - 1) / 100) * $BLOCKSIZE_Y; $lefts[] = fsubstr($v - 1, -2) * $BLOCKSIZE_X; } sort($tops); sort($lefts); reset($f_hidden); if (!$onlyarea) { if ($d['submit'] && !$d['reserved'] && $gdata['hoverimage']) { $imghover = '<image src="grids/u' . $d['userid'] . '.png?x=' . time() . '" border="0" id="tt' . $d['userid'] . 'b" style="position:absolute; top:' . $tops[0] . 'px; left:' . $lefts[0] . 'px;display:none" '; } if ($d['submit'] && !$d['reserved'] && $gdata['animated']) { $imganimasize = @getimagesize($dir . 'grids/u' . $d['userid'] . '.png'); $imganimapic = @file_exists($dir . 'grids/u' . $d['userid'] . '_orig' . $d['bildext']) ? '_orig' . $d['bildext'] : '.png'; $imganima = '<image src="grids/u' . $d['userid'] . $imganimapic . '?x=' . time() . '" border="0" id="tt' . $d['userid'] . 'b" style="position:absolute;top:' . $tops[0] . 'px; left:' . $lefts[0] . 'px;z-index:0" ' . $imganimasize[3] . ' '; } $CONFIG['reduce_memory'] = 1; if ($CONFIG['reduce_memory'] && @file_exists($dir . 'grids/u' . $d['userid'] . '.png')) { $src = imagecreatefrompng($dir . 'grids/u' . $d['userid'] . '.png'); } else { $src = imagecreatefromstring(base64_decode($d['bild'])); } if ($return === false || is_string($return)) { if ($CONFIG['reduce_memory'] && @file_exists($dir . 'grids/u' . $d['userid'] . '.png')) { $src_pre = imagecreatefrompng($dir . 'grids/u' . $d['userid'] . '.png'); } else { $src_pre = imagecreatefromstring(base64_decode($d['bild'])); } for ($i = 0; $i < imagecolorstotal($src_pre); $i++) { $f = imagecolorsforindex($src_pre, $i); $gst = ($f["red"] + $f["green"] + $f["blue"]) / 3; imagecolorset($src_pre, $i, $gst, $gst, $gst); } } $RES = false; } while (list(, $v) = each($f_hidden)) { $top = (int) (($v - 1) / 100) * $BLOCKSIZE_Y + $y_plus; $left = fsubstr($v - 1, -2) * $BLOCKSIZE_X + $x_plus; if (!$start) { $start = "{$left},{$top}"; $ende = "{$left}," . ($top + $BLOCKSIZE_Y); $x = $left; $y = $top; } if (!$only_premap) { if ($d['submit'] && !$d['reserved']) { if (!$onlyarea) { imagecopymerge($dest, $src, $left, $top, $left - $lefts[0], $top - $tops[0], $BLOCKSIZE_X, $BLOCKSIZE_Y, $gdata['transparency']); } $koordinaten["{$left},{$top}"] = true; $koordinaten[$left + $BLOCKSIZE_X . ",{$top}"] = true; $koordinaten[$left + $BLOCKSIZE_X . "," . ($top + $BLOCKSIZE_Y)] = true; $koordinaten["{$left}," . ($top + $BLOCKSIZE_Y)] = true; } elseif ($gdata['reserve_pixel'] && !$onlyarea) { if ((int) $gdata['transparency'] > 0) { imagecopymerge($dest, $src_reserved, $left, $top, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $gdata['transparency']); } elseif (function_exists("imagecopyresampled")) { imagecopyresampled($dest, $src_reserved, $left, $top, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $BLOCKSIZE_X, $BLOCKSIZE_Y); } else { imagecopyresized($dest, $src_reserved, $left, $top, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $BLOCKSIZE_X, $BLOCKSIZE_Y); } } } if ($return === false || is_string($return)) { if ($d['submit'] && !$d['reserved'] && !$onlyarea) { imagecopymerge($dest_premap, $src_pre, $left, $top, $left - $lefts[0], $top - $tops[0], $BLOCKSIZE_X, $BLOCKSIZE_Y, $gdata['transparency_grey']); } elseif (!$onlyarea) { if ((int) $gdata['transparency_grey'] > 0) { imagecopymerge($dest_premap, $src_reserved, $left, $top, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $gdata['transparency_grey']); } elseif (function_exists("imagecopyresampled")) { imagecopyresampled($dest_premap, $src_reserved, $left, $top, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $BLOCKSIZE_X, $BLOCKSIZE_Y); } else { imagecopyresized($dest_premap, $src_reserved, $left, $top, 0, 0, $BLOCKSIZE_X, $BLOCKSIZE_Y, $BLOCKSIZE_X, $BLOCKSIZE_Y); } } if (!$RES && (!$d['submit'] || $d['reserved']) && $gdata['reserve_char'] && $gdata['reserve_charcolor'] && !$onlyarea) { $RES = true; $rgb = hex2rgb($gdata['reserve_charcolor']); imageString($dest_premap, $gdata['reserve_charsize'], $left + 2, $top + 2, $gdata['reserve_char'], ImageColorAllocate($dest_premap, $rgb[0], $rgb[1], $rgb[2])); if ($gdata['reserve_pixel']) { imageString($dest, $gdata['reserve_charsize'], $left + 2, $top + 2, $gdata['reserve_char'], ImageColorAllocate($dest, $rgb[0], $rgb[1], $rgb[2])); } } } } if (!$onlyarea) { if ($return === false || is_string($return)) { @imagedestroy($src_pre); } @imagedestroy($src); } if ($koordinaten && !$nomap) { $imap = array(); $imap[0] = $start; $nrichtung = 4; $lrichtung = 2; do { if ($koordinaten["{$x}," . ($y - $BLOCKSIZE_Y)] && !in_array("{$x}," . ($y - $BLOCKSIZE_Y), $imap) && $nrichtung == 1) { if ($lrichtung != 1) { $imap[] = "{$x},{$y}"; } $nrichtung = 3; $lrichtung = 1; $y -= $BLOCKSIZE_Y; } elseif ($koordinaten[$x + $BLOCKSIZE_X . ",{$y}"] && !in_array($x + $BLOCKSIZE_X . ",{$y}", $imap) && $nrichtung == 2) { if ($lrichtung != 2) { $imap[] = "{$x},{$y}"; } $nrichtung = 0; $lrichtung = 2; $x += $BLOCKSIZE_X; } elseif ($koordinaten["{$x}," . ($y + $BLOCKSIZE_Y)] && !in_array("{$x}," . ($y + $BLOCKSIZE_Y), $imap) && $nrichtung == 3) { if ($lrichtung != 3) { $imap[] = "{$x},{$y}"; } $nrichtung = 1; $lrichtung = 3; $y += $BLOCKSIZE_Y; } elseif ($koordinaten[$x - $BLOCKSIZE_X . ",{$y}"] && !in_array($x - $BLOCKSIZE_X . ",{$y}", $imap) && $nrichtung == 4) { if ($lrichtung != 4) { $imap[] = "{$x},{$y}"; } $nrichtung = 2; $lrichtung = 4; $x -= $BLOCKSIZE_X; } $nrichtung = $nrichtung == 4 ? 1 : $nrichtung + 1; } while ("{$x},{$y}" != $ende && $i++ < 10000); $imap[] = $ende; $href = !$gdata['real_url'] || empty($d['url']) ? 'index.php?u=' . $d['userid'] : $d['url']; $hits = $gdata['track_clicks'] && $gdata['show_clicks'] ? ' (' . $d['hits'] . ')' : ''; $hits_tt = $gdata['track_clicks'] && $gdata['show_clicks'] ? $d['hits'] : ''; if (empty($d['target'])) { $blank = $gdata['new_window'] ? ' target="_blank"' : ''; } else { $blank = ' target="' . htmlspecialchars($d['target'], ENT_QUOTES) . '"'; } $onMouseOut = 'onMouseOut="htoo(\'tt' . $d['userid'] . 'a\')"'; $title = $gdata['show_box'] ? ' onMouseOver="stoo(\'tt' . $d['userid'] . '\')" ' . (!$imghover ? $onMouseOut : '') : 'title="' . htmlspecialchars(stripslashes($d['title'])) . $hits . '" ' . ($imghover ? 'onMouseOver="document.getElementById(\'tt' . $d['userid'] . 'b\').style.display = \'block\';if(bi) bi.style.display=\'none\'" onMouseOut="document.getElementById(\'tt' . $d['userid'] . 'b\').style.display = \'none\'"' : ''); if (!$d['title']) { $d['title'] = $d['url']; } $tooltipcontent = eregi_replace('_TITLE_', stripslashes($d['title']), stripslashes($gdata['tooltip_layout'])); $tooltipcontent = eregi_replace('_HITS_', $hits_tt, $tooltipcontent); $tooltipcontent = eregi_replace('_PIXEL_', '<img src="grids/u' . $d['userid'] . '.png?x=' . time() . '">', $tooltipcontent); $endung = stristr($tooltipcontent, '_IMAGE_') && !@file_exists($dir . 'grids/u' . $d['userid'] . '_orig' . $d['bildext']) || !$gdata['image_saveorig'] ? '.png' : '_orig' . $d['bildext']; $tooltipcontent = eregi_replace('_IMAGE_', '<img src="grids/u' . $d['userid'] . $endung . '?x=' . time() . '">', $tooltipcontent); $onClick = $gdata['real_url'] && !empty($d['url']) ? ' onClick="window.open(\'index.php?u=' . $d['userid'] . '\',\'' . htmlspecialchars($d['target'], ENT_QUOTES) . '\');return false"' : ''; if ($gdata['popup'] && empty($d['url'])) { $href = 'javascript:P(\'' . $href . '\',\'' . $d['userid'] . '\',\'sr\',' . (int) $gdata['popup_width'] . ',' . (int) $gdata['popup_height'] . ')'; $blank = ''; } $tooltips[] = '<div class="tooltip_' . $gdata['gridid'] . '" id="tt' . $d['userid'] . '">' . $tooltipcontent . '</div>'; $imagemap[] = '<area shape="poly" coords="' . @implode(',', $imap) . '" href="' . $href . '" ' . $title . $blank . $onClick . '>'; if ($imghover) { $imagehover[] = '<a href="' . $href . '"' . $blank . $onClick . '>' . $imghover . ' ' . ($gdata['show_box'] ? 'onMouseOver="an=false;stoo(\'tt' . $d['userid'] . '\')" ' . $onMouseOut . '"></a>' : 'onMouseOver="this.style.display = \'block\';bi=document.getElementById(\'tt' . $d['userid'] . 'b\')" onMouseOut="this.style.display = \'none\'"'); } if ($imganima) { $imganimate[] = '<a href="' . $href . '"' . $blank . $onClick . '>' . $imganima . ' ' . ($gdata['show_box'] ? 'onMouseOver="an=true;stoo(\'tt' . $d['userid'] . '\')" ' . $onMouseOut . '"></a>' : ''); } } } @imagedestroy($src_reserved); $quality = $gdata['image_reduce'] && $gdata['image_format'] == 2 ? '75' : '100'; if (!$only_premap) { if (!$onlyarea) { if ($gdata['image_interlace']) { imageinterlace($dest, 1); } if ($gdata['image_reduce'] && function_exists("imagetruecolortopalette") && $gdata['image_format'] == 1) { imagetruecolortopalette($dest, true, 256); } $gridsavepath = $dir . 'grids/grid_' . $gdata['gridid'] . '.' . $iformat[$gdata['image_format']]; $pregridsavepath = $dir . 'grids/pregrid_' . $gdata['gridid'] . '.' . $iformat[$gdata['image_format']]; $areasavepath = $dir . 'grids/area_' . $gdata['gridid'] . '.htm'; if ($return && is_string($return)) { $gridsavepath = $dir . $return . '/grid_' . $gdata['gridid'] . '.' . $iformat[$gdata['image_format']]; $pregridsavepath = $dir . $return . '/pregrid_' . $gdata['gridid'] . '.' . $iformat[$gdata['image_format']]; $areasavepath = $dir . $return . '/area_' . $gdata['gridid'] . '.htm'; } elseif ($return === true) { $gridsavepath = false; $pregridsavepath = false; $areasavepath = false; } if ($gridsavepath) { if ($gdata['image_format'] == 1) { imagepng($dest, $gridsavepath); } elseif ($gdata['image_format'] == 2) { imagejpeg($dest, $gridsavepath, $quality); } elseif ($gdata['image_format'] == 3) { imagegif($dest, $gridsavepath); } } else { if ($gdata['image_format'] == 1) { header("Content-type: image/png"); imagepng($dest); } elseif ($gdata['image_format'] == 2) { header("Content-type: image/jpeg"); imagejpeg($dest, '', $quality); } elseif ($gdata['image_format'] == 3) { header("Content-type: image/gif"); imagegif($dest); } } if ($return === false) { $small_width = 200; $small_height = 200; $orig_height = round($small_width * $height / $width); if ($orig_height > $small_height) { $small_width = round($width / ($height / $small_height)); $orig_height = $small_height; } if (!($admin_dest = @imagecreatetruecolor($small_width, $orig_height))) { $admin_dest = imagecreate($small_width, $orig_height); } if (!@imagecopyresampled($admin_dest, $dest, 0, 0, 0, 0, $small_width, $orig_height, $width, $height)) { imagecopyresized($admin_dest, $dest, 0, 0, 0, 0, $small_width, $orig_height, $width, $height); } imagepng($admin_dest, $dir . 'grids/grid_' . $gdata['gridid'] . '_small.png'); imagedestroy($admin_dest); } imagedestroy($dest); } $toolt = '<style> .tooltip_' . $gdata['gridid'] . ' { position:absolute;z-index:1;display:none; ' . stripslashes($gdata['tooltip_style']) . ' } </style> '; if ($areasavepath) { $handle = fopen($areasavepath, "w"); if ($tooltips) { fwrite($handle, $toolt . implode(" ", $tooltips)); } if ($imagemap) { fwrite($handle, implode(" ", $imagemap)); } if ($imagehover) { fwrite($handle, implode(" ", $imagehover)); } if ($imganimate) { fwrite($handle, implode(" ", $imganimate)); } fclose($handle); } elseif ($onlyarea) { if ($tooltips) { print $toolt . implode(" ", $tooltips); } if ($imagemap) { print implode(" ", $imagemap); } } } if ($pregridsavepath) { if ($gdata['image_interlace']) { imageinterlace($dest_premap, 1); } if ($gdata['image_reduce'] && function_exists("imagetruecolortopalette") && $gdata['image_format'] == 1) { imagetruecolortopalette($dest_premap, true, 256); } if ($gdata['image_format'] == 1) { imagepng($dest_premap, $pregridsavepath); } elseif ($gdata['image_format'] == 2) { imagejpeg($dest_premap, $pregridsavepath, $quality); } elseif ($gdata['image_format'] == 3) { imagegif($dest_premap, $pregridsavepath); } imagedestroy($dest_premap); return true; } }
/** * Creates error image based on gfx/notfound_thumb.png * Requires GD lib enabled, otherwise it will exit with the three * textstrings outputted as text. Outputs the image stream to browser and exits! * * @param string $filename Name of the file * @param string $textline1 Text line 1 * @param string $textline2 Text line 2 * @param string $textline3 Text line 3 * @return void * @throws \RuntimeException */ public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3) { if (empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'])) { throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952); } // Creates the basis for the error image $basePath = ExtensionManagementUtility::extPath('core') . 'Resources/Public/Images/'; if (!empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'])) { $im = imagecreatefrompng($basePath . 'NotFound.png'); } else { $im = imagecreatefromgif($basePath . 'NotFound.gif'); } // Sets background color and print color. $white = imageColorAllocate($im, 255, 255, 255); $black = imageColorAllocate($im, 0, 0, 0); // Prints the text strings with the build-in font functions of GD $x = 0; $font = 0; if ($textline1) { imagefilledrectangle($im, $x, 9, 56, 16, $white); imageString($im, $font, $x, 9, $textline1, $black); } if ($textline2) { imagefilledrectangle($im, $x, 19, 56, 26, $white); imageString($im, $font, $x, 19, $textline2, $black); } if ($textline3) { imagefilledrectangle($im, $x, 29, 56, 36, $white); imageString($im, $font, $x, 29, substr($textline3, -14), $black); } // Outputting the image stream and exit if (!empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'])) { imagePng($im, $filename); } else { imageGif($im, $filename); } }
<?php /** * @mario <*****@*****.**> **/ $strrand = md5(rand()); $str = substr($strrand, 0, 6); $im = @imagecreatetruecolor(100, 50); for ($a = 0; $a < 6; $a++) { imageString($im, 5, 9 + 15 * $a, 7 * rand(1, 3), $str[$a], imagecolorallocate($im, rand(100, 255), rand(100, 255), rand(100, 255))); imageline($im, rand(0, 100), rand(0, 50), rand(0, 100), rand(0, 50), imagecolorallocate($im, rand(25, 255), rand(25, 255), rand(25, 255))); } imagerectangle($im, 0, 0, imagesx($im) - 1, imagesy($im) - 1, imagecolorallocate($im, 0, 0, 0)); imagerectangle($im, 1, 1, imagesx($im) - 2, imagesy($im) - 2, imagecolorallocate($im, 255, 255, 255)); header("Content-type: image/png"); imagepng($im); imagedestroy($im); session_start(); $_SESSION['captcha'] = $str;
<?php ## Создание картинки "на лету". // Получаем строку, которую нам передали в параметрах $string = $_SERVER['QUERY_STRING'] ?? "Hello, world!"; // Загружаем рисунок фона с диска. $im = imageCreateFromGif("button.gif"); // Создаем в палитре новый цвет - черный. $color = imageColorAllocate($im, 0, 0, 0); // Вычисляем размеры текста, который будет выведен. $px = (imageSX($im) - 6.5 * strlen($string)) / 2; // Выводим строку поверх того, что было в загруженном изображении. imageString($im, 3, $px, 1, $string, $color); // Сообщаем о том, что далее следует рисунок PNG. header("Content-type: image/png"); // Теперь - самое главное: отправляем данные картинки в // стандартный выходной поток, т. е. в браузер. imagePng($im); // В конце освобождаем память, занятую картинкой. imageDestroy($im);
$titrePolice=2; $i++; } for($i=0;$i<$fin-1;$i++){ImageLine($image, $points[$i][0],$points[$i][1],$points[$i+1][0],$points[$i+1][1],$rouge);} for($i=0;$i<$fin;$i++) { if (!isset($place[$i+1])){imageString($image, $titrePolice, $points[$i][0],$points[$i][1] , $place[$i], $rouge);} elseif ($place[$i+1]<=$place[$i]){imageString($image, $titrePolice, $points[$i][0],$points[$i][1] , $place[$i], $rouge);} elseif ($place[$i+1]>$place[$i]){imageString($image, $titrePolice, $points[$i][0],$points[$i][1]-11 , $place[$i], $rouge);} else {imageString($image, $titrePolice, $points[$i][0], $points[$i][1], $place[$i], $rouge);} } $titre = ""; $titrePolice = 4; imageString($image, $titrePolice, ($largeur+$marge_gauche-ImageFontWidth($titrePolice)*strlen($titre))/2, $hauteur+30, $titre, $vert); ImagePNG($image); ImageDestroy($image); ?>
} // we cannot delete it here because we need to revershe check it once they submit the form //$oDb->delete(Phpfox::getT('upload_track'),'user_hash = "' . $sHash . '"'); $sFile = Phpfox::getParam('user.dir_user_spam') . $sPath; $_GET['ext'] = 'jpeg'; } else { preg_match('/_[0-9]+/', $_GET['file'], $aSize); } $sFile = preg_replace('/%s/', !empty($aSize[0]) ? $aSize[0] : '', $sFile); if (file_exists($sFile)) { ob_clean(); header('Content-Type: image/' . $_GET['ext']); echo file_get_contents($sFile); ob_end_flush(); exit; } else { header("HTTP/1.0 404 Not Found"); $sText = 'Not Found!'; $nW = 100; $nH = 30; $nLeft = 5; $nTop = 5; $hImg = imageCreate($nW, $nH); $nBgColor = imageColorAllocate($hImg, 0, 0, 0); $nTxtColor = imageColorAllocate($hImg, 255, 255, 255); imageString($hImg, 5, $nLeft, $nTop, $sText, $nTxtColor); ob_clean(); header('Content-Type: image/jpeg'); imagejpeg($hImg); exit; }
/** * 生成验证码使用GD * @param $img_width * @param $img_height * @return unknown_type */ static function verifycode_gd($img_width = 80, $img_height = 30) { $authnum = ''; srand(microtime() * 100000); for ($Tmpa = 0; $Tmpa < 4; $Tmpa++) { $authnum .= dechex(rand(0, 15)); } $authnum = strtoupper($authnum); $_SESSION['authcode'] = $authnum; $aimg = imageCreate($img_width, $img_height); //生成图片 ImageColorAllocate($aimg, 255, 255, 255); //图片底色,ImageColorAllocate第1次定义颜色PHP就认为是底色了 //下面该生成雪花背景了,其实就是在图片上生成一些符号 for ($i = 1; $i <= 128; $i++) { imageString($aimg, 1, mt_rand(1, $img_width), mt_rand(1, $img_height), "*", imageColorAllocate($aimg, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255))); //其实也不是雪花,就是生成*号而已。为了使它们看起来"杂乱无章、5颜6色",就得在1个1个生成它们的时候,让它们的位置、颜色,甚至大小都用随机数,rand()或mt_rand都可以完成。 } for ($i = 0; $i < strlen($_SESSION['authcode']); $i++) { imageString($aimg, mt_rand(8, 12), $i * $img_width / 4 + mt_rand(1, 8), mt_rand(1, $img_height / 4), $_SESSION['authcode'][$i], imageColorAllocate($aimg, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200))); } ImagePng($aimg); //生成png格式 ImageDestroy($aimg); }
$thisDate = getDate($diagramDate); $xCoord = $diagramWidth / $daysToShow * $i; // draw day mark and day number imageLine($image, $xCoord, $diagramHeight - 25, $xCoord, $diagramHeight - 20, $colorGrid); imageString($image, 3, $xCoord - 5, $diagramHeight - 16, $thisDate["mday"], $colorGrid); $diagramDate += $nrSecondsPerDay; } // draw rectangle around diagram (marks its boundaries) imageRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 20, $colorGrid); // draw middle cross imageLine($image, 0, ($diagramHeight - 20) / 2, $diagramWidth, ($diagramHeight - 20) / 2, $colorCross); imageLine($image, $diagramWidth / 2, 0, $diagramWidth / 2, $diagramHeight - 20, $colorCross); // print descriptive text into the diagram imageString($image, 3, 10, 10, $TEXT['bio-birthday'] . ": {$birthDay}.{$birthMonth}.{$birthYear}", $colorCross); imageString($image, 3, 10, 26, $TEXT['bio-today'] . ": " . date("d.m.Y"), $colorCross); imageString($image, 3, 10, $diagramHeight - 42, $TEXT['bio-physical'], $colorPhysical); imageString($image, 3, 10, $diagramHeight - 58, $TEXT['bio-emotional'], $colorEmotional); imageString($image, 3, 10, $diagramHeight - 74, $TEXT['bio-intellectual'], $colorIntellectual); // now draw each curve with its appropriate parameters drawRhythm($daysGone, 23, $colorPhysical); drawRhythm($daysGone, 28, $colorEmotional); drawRhythm($daysGone, 33, $colorIntellectual); // set the content type header("Content-Type: image/png"); // create an interlaced image for better loading in the browser imageInterlace($image, 1); // mark background color as being transparent imageColorTransparent($image, $colorBackgr); // now send the picture to the client (this outputs all image data directly) imagePNG($image); exit;
/** * Creates error image based on gfx/notfound_thumb.png * Requires GD lib enabled, otherwise it will exit with the three * textstrings outputted as text. Outputs the image stream to browser and exits! * * @param string $filename Name of the file * @param string $textline1 Text line 1 * @param string $textline2 Text line 2 * @param string $textline3 Text line 3 * @return void * @throws \RuntimeException * * @internal Don't use this method from outside the LocalImageProcessor! */ public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3) { if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952); } // Creates the basis for the error image if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { $im = imagecreatefrompng(PATH_typo3 . 'gfx/notfound_thumb.png'); } else { $im = imagecreatefromgif(PATH_typo3 . 'gfx/notfound_thumb.gif'); } // Sets background color and print color. $white = imageColorAllocate($im, 255, 255, 255); $black = imageColorAllocate($im, 0, 0, 0); // Prints the text strings with the build-in font functions of GD $x = 0; $font = 0; if ($textline1) { imagefilledrectangle($im, $x, 9, 56, 16, $white); imageString($im, $font, $x, 9, $textline1, $black); } if ($textline2) { imagefilledrectangle($im, $x, 19, 56, 26, $white); imageString($im, $font, $x, 19, $textline2, $black); } if ($textline3) { imagefilledrectangle($im, $x, 29, 56, 36, $white); imageString($im, $font, $x, 29, substr($textline3, -14), $black); } // Outputting the image stream and exit if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) { imagePng($im, $filename); } else { imageGif($im, $filename); } }
function SetCheckCodes() { $x_size = 90; $y_size = 30; if (function_exists("imagecreate")) { $aimg = imagecreate($x_size, $y_size); $back = imagecolorallocate($aimg, 255, 255, 255); $border = imagecolorallocate($aimg, 0, 0, 0); imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back); $txt = "0123456789"; $txtlen = strlen($txt); $thetxt = ""; for ($i = 0; $i < 4; $i++) { $randnum = mt_rand(0, $txtlen - 1); $randang = mt_rand(-20, 20); //文字旋转角度 $rndtxt = substr($txt, $randnum, 1); $thetxt .= $rndtxt; $rndx = mt_rand(2, 7); $rndy = mt_rand(0, 9); $colornum1 = $rndx * $rndx * $randnum % 255; $colornum2 = $rndy * $rndy * $randnum % 255; $colornum3 = $rndx * $rndy * $randnum % 255; $newcolor = imagecolorallocate($aimg, $colornum1, $colornum2, $colornum3); imageString($aimg, 5, $rndx + $i * 21, 5 + $rndy, $rndtxt, $newcolor); } unset($txt); $thetxt = strtolower($thetxt); $_SESSION["qgLoginChk"] = md5($thetxt); #[写入session中] @session_write_close(); #[关闭session写入] imagerectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $border); $newcolor = ""; $newx = ""; $newy = ""; $pxsum = 100; //干扰像素个数 for ($i = 0; $i < $pxsum; $i++) { $newcolor = imagecolorallocate($aimg, mt_rand(0, 254), mt_rand(0, 254), mt_rand(0, 254)); imagesetpixel($aimg, mt_rand(0, $x_size - 1), mt_rand(0, $y_size - 1), $newcolor); } header("Pragma:no-cache"); header("Cache-control:no-cache"); header("Content-type: image/png"); imagepng($aimg); imagedestroy($aimg); exit; } }
} else { $width = imageFontWidth(5); $height = imageFontHeight(5); if ($x + (strlen($user) + 1) * $width > 500) { $stringx = $x - (strlen($user) + 1) * $width - 12; } if ($y + $height > 500) { $stringy = $y - $height / 2 - 2; } $magenta = imageColorAllocate($map, 255, 0, 255); imageColorTransparent($map, $magenta); $brown = imagecolorallocate($map, 102, 51, 0); $parchment = imagecolorallocate($map, 255, 255, 204); // Avoid drawing a brown dot on a brown area $rgb = imageColorAt($map, $x, $y); if ($rgb > 0) { // $rgb is 0 on our parchment-colored areas $temp = $brown; $brown = $parchment; $parchment = $temp; } // YOU ARE HERE imageFilledEllipse($map, $x, $y, 6, 6, $brown); // background for text imageFilledRectangle($map, $stringx + 6, $stringy - $height / 2, $stringx + 6 + $width * (strlen($user) + 1), $stringy + $height / 2, $brown); // text itself imageString($map, 5, $stringx + 7 + $width / 2, $stringy - $height / 2 - 1, $user, $parchment); } header("Content-type: image/png"); imagePNG($map); imageDestroy($map);
if (intval($z) > 13) { $fac = pow(2, $z - 13); $x = (int) ($x / $fac); $y = (int) ($y / $fac); $file = $base . "packed/" . $x . "/" . $y . ".pack"; } else { $file = $base . $z . "/" . $x . "/" . $y . ".png"; } $string = date("Y-m-d H:i:s", filemtime($file)); $iwidth = 256; $iheight = 128; // create empty image $img = ImageCreateTrueColor($iwidth, $iheight); $transparentCol = imagecolorallocate($img, 255, 255, 0); imagefilledrectangle($img, 0, 0, $iwidth, $iheight, $transparentCol); imagecolortransparent($img, $transparentCol); // write text $font = 16; $width = imageFontWidth($font) * strlen($string); $height = imageFontHeight($font); $x = imagesx($img) - $width; $y = imagesy($img) - 2 * $height; $backgroundColor = imagecolorallocate($img, 255, 255, 255); $textColor = imagecolorallocate($img, 0, 0, 0); imageString($img, $font, $x - 1, $y - 1, $string, $backgroundColor); imageString($img, $font, $x - 1, $y + 1, $string, $backgroundColor); imageString($img, $font, $x + 1, $y + 1, $string, $backgroundColor); imageString($img, $font, $x + 1, $y - 1, $string, $backgroundColor); imageString($img, $font, $x, $y, $string, $textColor); //imageString ($img, $font, $x-50, $y-20, $file, $textColor); ImagePng($img);
msetcookie('08cms_regcode', authcode($timestamp . "\t" . $nmsg, 'ENCODE')); if (function_exists('imagecreate') && function_exists('imagecolorallocate') && function_exists('imagepng') && function_exists('imagesetpixel') && function_exists('imageString') && function_exists('imagedestroy') && function_exists('imagefilledrectangle') && function_exists('imagerectangle')) { $aimg = imagecreate($x_size, $y_size); $back = imagecolorallocate($aimg, 255, 255, 255); $border = imagecolorallocate($aimg, 183, 216, 239); imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back); imagerectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $border); for ($i = 1; $i <= 20; $i++) { $dot = imagecolorallocate($aimg, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255)); imagesetpixel($aimg, mt_rand(2, $x_size - 2), mt_rand(2, $y_size - 2), $dot); } for ($i = 1; $i <= 10; $i++) { imageString($aimg, 1, $i * $x_size / 12 + mt_rand(1, 3), mt_rand(1, 13), '.', imageColorAllocate($aimg, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255))); } for ($i = 0; $i < strlen($nmsg); $i++) { imageString($aimg, mt_rand(4, 5), $i * $x_size / 4 + mt_rand(1, 5), mt_rand(1, 6), $nmsg[$i], imageColorAllocate($aimg, mt_rand(50, 255), mt_rand(0, 120), mt_rand(50, 255))); } header("Pragma:no-cache"); header("Cache-control:no-cache"); header("Content-type: image/png"); imagepng($aimg); imagedestroy($aimg); exit; } else { header("Pragma:no-cache"); header("Cache-control:no-cache"); header("ContentType: Image/BMP"); $Color[0] = chr(0) . chr(0) . chr(0); $Color[1] = chr(255) . chr(255) . chr(255); $_Num[0] = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"; $_Num[1] = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111";
{ imageline($im, $i*$xstep + $dx, $dy + 10, $i*$xstep + $dx, $ysize-$dy, $silver); if (($i % 5) == 0) { imageline($im, $i*$xstep + $dx, $dy + 10, $i*$xstep + $dx, $ysize-$dy, $gray); $mydate = ($timenow - 86400*31) + $i * 86400; $mydate = date("m.d", $mydate); imageString($im, 1, $i*$xstep + $dx, $ysize - $dy + 12, $mydate, $black); } } //далаем разметку по oy for ($i=0; $i<=10; $i++) { imageline($im, $dx, $ysize - $dy - $i*$ystep, $xsize-$dx, $ysize - $dy - $i*$ystep, $silver); imageString($im, 1, 0, $ysize - $dy - $i*$ystep, $i*$max/10, $black); } //сами оси imageline($im, $dx, $dy, $dx, $ysize-$dy, $black); imageline($im, $dx, $ysize-$dy, $xsize-$dx, $ysize-$dy, $black); $i=1; foreach ($users as $user){ user_data($user, $i,$shopcoins_class); $i++; } ImagePNG($im); ImageDestroy($im);
$i = imageCreateTrueColor(500, 300); /* Подготовка к работе */ imageAntiAlias($i, true); $red = imageColorAllocate($i, 255, 0, 0); $white = imageColorAllocate($i, 0xff, 0xff, 0xff); $black = imageColorAllocate($i, 0, 0, 0); $green = imageColorAllocate($i, 0, 255, 0); $blue = imageColorAllocate($i, 0, 0, 255); $grey = imageColorAllocate($i, 192, 192, 192); imageFill($i, 0, 0, $grey); /* Рисуем примитивы */ imageSetPixel($i, 10, 10, $black); imageLine($i, 20, 20, 280, 180, $red); imageRectangle($i, 20, 20, 280, 180, $blue); //array of dots $points = [120, 120, 100, 200, 300, 200]; imagePolygon($i, $points, 3, $green); imageEllipse($i, 200, 150, 300, 200, $red); // imageArc($i, 210, 160, 300, 200, 0, 90, $black); imageFilledArc($i, 200, 150, 300, 200, 0, 40, $red, IMG_ARC_PIE); /* Рисуем текст */ imageString($i, 5, 150, 200, 'php7', $black); imageCharUp($i, 3, 200, 200, 'PHP5', $blue); imageTtfText($i, 30, 10, 300, 150, $green, 'arial.ttf', 'PHP7'); /* Отдаем изображение */ // header("Content-type: image/gif"); // imageGif($i); header("Content-type: image/png"); imagePng($i); //header("Content-type: image/jpg"); //imageJpeg($i);