private function getCreateImage() { $this->image = imageCreate($this->width, $this->height); $background = imageColorAllocate($this->image, 255, 255, 255); $border = imageColorAllocate($this->image, 0, 0, 0); imageRectangle($this->image, 0, 0, $this->width - 1, $tihs->height - 1, $border); }
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); }
private function getCreateImage() { //用来创建图像资源,并初使化背影 $this->image = imageCreate($this->width, $this->height); $back = imageColorAllocate($this->image, 255, 255, 255); $border = imageColorAllocate($this->image, 0, 0, 0); imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $border); }
private function getCreateImage() { //用来创建图像资源,并初使化背影 $this->image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($this->image, rand(225, 255), rand(225, 255), rand(225, 255)); //背景色(随机) @imagefill($this->image, 0, 0, $backColor); $border = imageColorAllocate($this->image, 0, 0, 0); imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $border); }
private function getCreateImage() { //创建指定大小的画布(基于调色板) $this->image = imageCreate($this->width, $this->height); //设置颜色(白色) $back = imagecolorallocate($this->image, 255, 255, 255); //设置颜色(黑色) $border = imagecolorallocate($this->image, 0, 0, 0); //在图像中绘制一个矩形 imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $border); }
private function create_pix() { for ($i = 0; $i < 3; $i++) { imageline($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $this->font_color_res); } for ($i = 0; $i < 2; $i++) { imageEllipse($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), 100, 100, $this->font_color_res); } for ($i = 0; $i < 100; $i++) { imagesetpixel($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), $this->font_color_res); } imageRectangle($this->img, 0, 0, $this->width - 1, $this->height - 1, $this->font_color_res); }
public function getPNG() { // создаем картинку $image = imageCreate($this->width + $this->widthLegend, $this->height); $backColor = imageColorAllocate($image, $this->colorBG >> 16, ($this->colorBG >> 8) % 256, $this->colorBG % 256); $centerColor = imageColorAllocate($image, $this->colorCenter >> 16, ($this->colorCenter >> 8) % 256, $this->colorCenter % 256); $pointsColor = imageColorAllocate($image, $this->colorPoints >> 16, ($this->colorPoints >> 8) % 256, $this->colorPoints % 256); $legendColor = imageColorAllocate($image, $this->colorLegend >> 16, ($this->colorLegend >> 8) % 256, $this->colorLegend % 256); // background imageFilledRectangle($image, 0, 0, $this->width, $this->height, $backColor); imageRectangle($image, $this->width, 0, $this->widthLegend + $this->width - 1, $this->height - 1, $legendColor); // добавляем масштаб в легенду imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2 - 1, $this->width + 10, $this->height - $this->fontSize * 2 + 1, $legendColor); imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2, $this->width + 20, $this->height - $this->fontSize * 2, $legendColor); imageLine($image, $this->width + 20, $this->height - $this->fontSize * 2 - 1, $this->width + 20, $this->height - $this->fontSize * 2 + 1, $legendColor); imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize + 20, $this->height - $this->fontSize * 1.5, $legendColor, $this->pathToFont, "{$this->metersIn10Pix} {$this->metersLabel}"); // center imageFilledEllipse($image, $this->centerWidth, $this->centerHeight, $this->sizePoints, $this->sizePoints, $centerColor); imageTTFText($image, $this->fontSize, 0, $this->centerWidth, $this->centerHeight + $this->fontSize + $this->sizePoints, $centerColor, $this->pathToFont, "0"); imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2, $legendColor, $this->pathToFont, "0 - {$this->centerLabel}"); // points $i = 1; foreach ($this->pointsBased as $v) { $angle = $v->getPoint()->getAzimuth() - 90; // угол для тригонометрии $pointWidth = $this->centerWidth + $this->k * ($v->getPoint()->getDistance() * cos(deg2rad($angle))); $pointHeight = $this->centerHeight + $this->k * ($v->getPoint()->getDistance() * sin(deg2rad($angle))); // рисуем точку imageEllipse($image, $pointWidth, $pointHeight, $this->sizePoints, $this->sizePoints, $pointsColor); // подпись imageTTFText($image, $this->fontSize, 0, $pointWidth, $pointHeight + $this->fontSize + $this->sizePoints, $pointsColor, $this->pathToFont, $i); // в легенду imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2 * ($i + 1), $legendColor, $this->pathToFont, "{$i} - " . $v->getTitle()); $i++; } ob_start(); imagePng($image); $str = ob_get_clean(); return $str; }
public static function show() { $width = self::$width; $height = self::$height; $len = self::$len; $bgcolor = self::$bgcolor; $noise = self::$noise; $noisenum = self::$noisenum; $border = self::$border; $bordercolor = self::$bordercolor; self::$_image = imageCreate($width, $height); $back = self::getcolor($bgcolor); imageFilledRectangle(self::$_image, 0, 0, $width, $height, $back); $size = $width / $len; if ($size > $height) { $size = $height; } $left = ($width - $len * ($size + $size / 10)) / $size; for ($i = 0; $i < $len; $i++) { $randtext = self::vchar(); self::$_code .= $randtext; $textColor = imageColorAllocate(self::$_image, rand(0, 100), rand(0, 100), rand(0, 100)); $font = dirname(__FILE__) . "/3.ttf"; $randsize = rand($size - $size / 5, $size - $size / 10); $location = $left + ($i * $size + $size / 10); imagettftext(self::$_image, $randsize, rand(-18, 18), $location, rand($size - $size / 100, $size + $size / 100), $textColor, $font, $randtext); } if ($noise == true) { self::setnoise(); } self::setCode(self::$_code); //setrawcookie("code",$code,time()+3600,"/"); //setcookie("code", $code, time()+120); $bordercolor = self::getcolor($bordercolor); if ($border == true) { imageRectangle(self::$_image, 0, 0, $width - 1, $height - 1, $bordercolor); } return self::$_image; }
/** * 显示验证码 * */ function show() { $this->image = imageCreate($this->width, $this->height); $this->back = $this->getColor($this->bgcolor); imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back); $size = $this->width / $this->charLen - 4; if ($size > $this->height) { $size = $this->height; } $left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5; $code = ''; for ($i = 0; $i < $this->charLen; $i++) { $randKey = rand(0, count($this->arrChr) - 1); $randText = $this->arrChr[$randKey]; $code .= $randText; $textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100)); $font = $this->fontPath . "1.ttf"; $randsize = rand($size - $size / 10, $size + $size / 10); $location = $left + ($i * $size + $size / 10); imagestring($this->image, mt_rand(3, 5), $location, 5, $randText, imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200))); //imagettftext($this->image, $randsize, rand(- 18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $code); } if ($this->showNoisePix == true) { $this->setNoisePix(); } if ($this->showNoiseLine == true) { $this->setNoiseLine(); } if ($this->showBorder == true) { $this->borderColor = $this->getColor($this->borderColor); imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor); } $this->CI->session->set_userdata('auth_code', $code); ob_clean(); header("Content-type: image/jpeg"); imagejpeg($this->image); imagedestroy($this->image); }
} } elseif ($sig_level < $configData['expbar_max_level'] || !$configData['expbar_max_hidden']) { // Variables to get and hold eXP bar data $outexp = printXP($sig_exp); $outperc = retPerc($sig_exp, $configData['expbar_loc_x'], $configData['expbar_length']); // Fix eXp bar text alignment if ($configData['expbar_align'] == 'center') { $exp_text_loc = $x_end - $configData['expbar_length'] / 2; } elseif ($configData['expbar_align'] == 'right') { $exp_text_loc = $x_end - 3; } else { $exp_text_loc = $configData['expbar_loc_x'] + 3; } // The eXP bar (outside border) if ($configData['expbar_disp_bdr']) { @imageRectangle($im, $configData['expbar_loc_x'] - 1, $configData['expbar_loc_y'] - 1, $x_end + 1, $y_end + 1, setColor($im, $configData['expbar_color_border'], $configData['expbar_trans_border'])) or debugMode(__LINE__, $php_errormsg); } // The eXP bar (inside box) if ($configData['expbar_disp_inside']) { @imageFilledRectangle($im, $configData['expbar_loc_x'], $configData['expbar_loc_y'], $x_end, $y_end, setColor($im, $configData['expbar_color_inside'], $configData['expbar_trans_inside'])) or debugMode(__LINE__, $php_errormsg); } // The progress bar @imageFilledRectangle($im, $configData['expbar_loc_x'], $configData['expbar_loc_y'], $outperc, $y_end, setColor($im, $configData['expbar_color_bar'], $configData['expbar_trans_bar'])) or debugMode(__LINE__, $php_errormsg); // eXpbar text if ($configData['expbar_disp_text']) { writeText($im, $configData['expbar_font_size'], $exp_text_loc, $y_end - 1, $configData['expbar_font_color'], $configData['expbar_font_name'], $configData['expbar_string_before'] . $outexp . $configData['expbar_string_after'], $configData['expbar_align'], $configData['expbar_text_shadow']); } } } #--[ PLACE DYNAMIC TEXT IN THE IMAGE ]------------------------------------- // Place the Character's Name
/* Создание изображения */ // $i = imageCreate(500, 300); $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);
public function border2($color = 0x0) { return imageRectangle($this->res, $this->offsetX, $this->offsetY, $this->sW + $this->offsetX, $this->sH + $this->offsetY, $this->hex2color($color)); }
* GNU General Public License as published by the Free Software Foundation, either version 3 of * * the License, or (at your option) any later version. This program is distributed in the hope * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. You should have received a copy of the GNU General Public License along with * * this program. If not, see <http://www.gnu.org/licenses/>. * **************************************************************************************************/ $alphabeth = array(); for ($i = ord('a'); $i <= ord('z'); $i++) { array_push($alphabeth, chr($i)); } for ($i = 0; $i <= 9; $i++) { array_push($alphabeth, $i); } $key = 'lolasd'; $randstr = ''; $cyph = urldecode(base64_decode($_GET['str'])); for ($i = 0; $i < 6; $i++) { $randstr .= $cyph[$i] ^ $key[$i % 6]; } $img = imageCreate(60, 30); $black = imageColorAllocate($img, 0, 0, 0); $white = imageColorAllocate($img, 255, 255, 255); imageRectangle($img, 0, 0, 99, 49, $white); imageString($img, 5, 2, 10, $randstr, $white); header("Content-type: image/png"); imagePng($img); imageDestroy($img); ?>
for ($i = 0; $i < $len; $i++) { $randtext = rand(0, 9); $code .= $randtext; $textColor = imageColorAllocate($image, rand(0, 100), rand(0, 100), rand(0, 100)); $font = rand(1, 4) . ".ttf"; $randsize = rand($size - $size / 10, $size + $size / 10); $location = $left + ($i * $size + $size / 10); imagettftext($image, $randsize, rand(-18, 18), $location, rand($size - $size / 10, $size + $size / 10), $textColor, $font, $randtext); } if ($noise == true) { setnoise(); } $_SESSION['cv_yzm'] = $code; $bordercolor = getcolor($bordercolor); if ($border == true) { imageRectangle($image, 0, 0, $width - 1, $height - 1, $bordercolor); } header("Content-type: image/png"); imagePng($image); imagedestroy($image); function getcolor($color) { global $image; $color = eregi_replace("^#", "", $color); $r = $color[0] . $color[1]; $r = hexdec($r); $b = $color[2] . $color[3]; $b = hexdec($b); $g = $color[4] . $color[5]; $g = hexdec($g); $color = imagecolorallocate($image, $r, $b, $g);
function draw_rectangle($x1, $y1, $x2, $y2, $color, $filled) { if ($filled) { imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color); } else { imageRectangle($this->image, $x1, $y1, $x2, $y2, $color); } }
/** * Function: drawRect * * Draws then given rectangle. Rounded is currently ignored. */ function drawRect($x, $y, $w, $h, $fill = null, $stroke = null, $shadow = false, $rounded = false, $dashed = false) { // TODO: Rounded rectangles if (isset($fill)) { if ($shadow) { imageFilledRectangle($this->image, $x + mxConstants::$SHADOW_OFFSETX, $y + mxConstants::$SHADOW_OFFSETY, $x + mxConstants::$SHADOW_OFFSETX + $w, $y + mxConstants::$SHADOW_OFFSETX + $h, $this->shadowColor); } $fill = $this->getColor($fill); imageFilledRectangle($this->image, $x, $y, $x + $w, $y + $h, $fill); } if (isset($stroke)) { if ($dashed) { $this->drawLine($x, $y, $x + $w, $y, $stroke, $dashed); $this->drawLine($x + $w, $y, $x + $w, $y + $h, $stroke, $dashed); $this->drawLine($x, $y + $h, $x + $w, $y + $h, $stroke, $dashed); $this->drawLine($x, $y + $h, $x, $y, $stroke, $dashed); } else { $stroke = $this->getColor($stroke); imageRectangle($this->image, $x, $y, $x + $w, $y + $h, $stroke); } } }
<?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 imageindex($x, $y, $idx, $sizex, $sizey) { $im = imageCreate($sizex, $sizey); $width = intval(($sizex - 2) / $x); $height = intval(($sizey - 2) / $y); $white = imageColorAllocate($im, 0xff, 0xff, 0xff); $black = imageColorAllocate($im, 0x0, 0x0, 0x0); $count = 0; for ($j = 0; $j < $y; $j++) { for ($i = 0; $i < $x; $i++) { $pointx = $i * $width; $pointy = $j * $height; if ($count++ == $idx) { imageFilledRectangle($im, $pointx, $pointy, $pointx + $width, $pointy + $height, $black); } else { imageRectangle($im, $pointx, $pointy, $pointx + $width, $pointy + $height, $black); } } } return $im; }
public function buildBody() { imageRectangle($this->img, 120, 100, 180, 180, 50); }
/** * 创建验证码图片 * * @return void */ function create() { $this->image = imageCreate($this->width, $this->height); $this->back = $this->getColor($this->bgcolor); imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back); $size = $this->width / $this->charLen - 4; if ($size > $this->height) { $size = $this->height; } $left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5; $code = ''; for ($i = 0; $i < $this->charLen; $i++) { $randKey = rand(0, count($this->arrChr) - 1); $randText = $this->arrChr[$randKey]; $code .= $randText; $textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100)); $font = $this->fontPath . '/' . rand(1, 5) . ".ttf"; $randsize = rand($size - $size / 10, $size + $size / 10); $location = $left + ($i * $size + $size / 10); @imagettftext($this->image, $randsize, rand(-18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $randText); } if ($this->showNoisePix == true) { $this->setNoisePix(); } if ($this->showNoiseLine == true) { $this->setNoiseLine(); } if ($this->showBorder == true) { $this->borderColor = $this->getColor($this->borderColor); imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor); } $this->text = strtolower($code); }
} if ($value >= $crit) { $colour = $ack ? $oRedAck : $oRed; } } else { if ($value <= $warn) { $colour = $ack ? $oYellowAck : $oYellow; } if ($value <= $crit) { $colour = $ack ? $oRedAck : $oRed; } } } // create box imagefilledrectangle($img, $offX, $offY + 1, $offX + $maxX, $offY + $maxY, $oGreen); imageRectangle($img, $offX, $offY, $offX + $maxX, $offY + $maxY, $oBlack); $maxX--; $maxY--; // "highlight" graph if non-ok value if ($colour != '') { imagefilledrectangle($img, $offX + 1, $offY + $sect3 + 1, $offX + $maxX, $offY + $maxY, $colour); } //================ // Normalize / Fix value and max //================ if ($value == null) { $value = $default; } else { if ($max != '' && $value < $min) { $value = $min; } elseif ($max != '' && $max != -1 && $value > $max) {
function Main($path, $width, $height, $dst_file, $header = false) { if (!isset($path)) { return array(0, "イメージのパスが設定されていません。"); } if (!file_exists($path)) { return array(0, "指定されたパスにファイルが見つかりません。"); } // 画像の大きさをセット if ($width) { $this->imgMaxWidth = $width; } if ($height) { $this->imgMaxHeight = $height; } $size = @GetimageSize($path); $re_size = $size; //アスペクト比固定処理 if ($this->imgMaxWidth != 0) { $tmp_w = $size[0] / $this->imgMaxWidth; } if ($this->imgMaxHeight != 0) { $tmp_h = $size[1] / $this->imgMaxHeight; } if ($tmp_w > 1 || $tmp_h > 1) { if ($this->imgMaxHeight == 0) { if ($tmp_w > 1) { $re_size[0] = $this->imgMaxWidth; $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0]; } } else { if ($tmp_w > $tmp_h) { $re_size[0] = $this->imgMaxWidth; $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0]; } else { $re_size[1] = $this->imgMaxHeight; $re_size[0] = $size[0] * $this->imgMaxHeight / $size[1]; } } } $imagecreate = function_exists("imagecreatetruecolor") ? "imagecreatetruecolor" : "imagecreate"; $imageresize = function_exists("imagecopyresampled") ? "imagecopyresampled" : "imagecopyresized"; switch ($size[2]) { // gif形式 case "1": if (function_exists("imagecreatefromgif")) { $src_im = imagecreatefromgif($path); $dst_im = $imagecreate($re_size[0], $re_size[1]); $transparent = imagecolortransparent($src_im); $colorstotal = imagecolorstotal($src_im); $dst_im = imagecreate($re_size[0], $re_size[1]); if (0 <= $transparent && $transparent < $colorstotal) { imagepalettecopy($dst_im, $src_im); imagefill($dst_im, 0, 0, $transparent); imagecolortransparent($dst_im, $transparent); } $imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); if (function_exists("imagegif")) { // 画像出力 if ($header) { header("Content-Type: image/gif"); imagegif($dst_im); return ""; } else { $dst_file = $dst_file . ".gif"; if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) { // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ) copy($path, $dst_file); } else { imagegif($dst_im, $dst_file); } } imagedestroy($src_im); imagedestroy($dst_im); } else { // 画像出力 if ($header) { header("Content-Type: image/png"); imagepng($dst_im); return ""; } else { $dst_file = $dst_file . ".png"; if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) { // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ) copy($path, $dst_file); } else { imagepng($dst_im, $dst_file); } } imagedestroy($src_im); imagedestroy($dst_im); } } else { // サムネイル作成不可の場合(旧バージョン対策) $dst_im = imageCreate($re_size[0], $re_size[1]); imageColorAllocate($dst_im, 255, 255, 214); //背景色 // 枠線と文字色の設定 $black = imageColorAllocate($dst_im, 0, 0, 0); $red = imageColorAllocate($dst_im, 255, 0, 0); imagestring($dst_im, 5, 10, 10, "GIF {$size['0']}x{$size['1']}", $red); imageRectangle($dst_im, 0, 0, $re_size[0] - 1, $re_size[1] - 1, $black); // 画像出力 if ($header) { header("Content-Type: image/png"); imagepng($dst_im); return ""; } else { $dst_file = $dst_file . ".png"; imagepng($dst_im, $dst_file); } imagedestroy($src_im); imagedestroy($dst_im); } break; // jpg形式 // jpg形式 case "2": $src_im = imageCreateFromJpeg($path); $dst_im = $imagecreate($re_size[0], $re_size[1]); $imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); // 画像出力 if ($header) { header("Content-Type: image/jpeg"); imageJpeg($dst_im); return ""; } else { $dst_file = $dst_file . ".jpg"; if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) { // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ) copy($path, $dst_file); } else { imageJpeg($dst_im, $dst_file); } } imagedestroy($src_im); imagedestroy($dst_im); break; // png形式 // png形式 case "3": $src_im = imageCreateFromPNG($path); $colortransparent = imagecolortransparent($src_im); $has_alpha = ord(file_get_contents($path, false, null, 25, 1)) & 0x4; if ($colortransparent > -1 || $has_alpha) { $dst_im = $imagecreate($re_size[0], $re_size[1]); // アルファチャンネルが存在する場合はそちらを使用する if ($has_alpha) { imagealphablending($dst_im, false); imagesavealpha($dst_im, true); } imagepalettecopy($dst_im, $src_im); imagefill($dst_im, 0, 0, $colortransparent); imagecolortransparent($dst_im, $colortransparent); imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } else { $dst_im = $imagecreate($re_size[0], $re_size[1]); imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); imagecolorstotal($src_im) == 0 ? $colortotal = 65536 : ($colortotal = imagecolorstotal($src_im)); imagetruecolortopalette($dst_im, true, $colortotal); } // 画像出力 if ($header) { header("Content-Type: image/png"); imagepng($dst_im); return ""; } else { $dst_file = $dst_file . ".png"; if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) { // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ) copy($path, $dst_file); } else { imagepng($dst_im, $dst_file); } } imagedestroy($src_im); imagedestroy($dst_im); break; default: return array(0, "イメージの形式が不明です。"); } return array(1, $dst_file); }
$farbe3 = mt_rand("0", "100"); // Verteile die Farben $rahmen = imageColorAllocate($bild, 0, 0, 0); // Rahmenfarbe $farbe = imageColorAllocate($bild, $farbe1, $farbe2, $farbe3); // Textfarbe // Hole die Zahlen der Punkte zum Zeichnen $alle_punkte = $size_x * $size_y / 15; // Zeichne viele Punkte mit der selben Farbe des Textes for ($zaehler = 0; $zaehler < $alle_punkte; $zaehler++) { // Erzeuge die Zufallspositionen der Punkte $pos_x = mt_rand("0", $size_x); $pos_y = mt_rand("0", $size_y); // Zeichne die Punkte imageSetPixel($bild, $pos_x, $pos_y, $farbe); } // Zeichne den Rahmen imageRectangle($bild, 0, 0, $size_x - 1, $size_y - 1, $rahmen); // Koordinaten der Position von der Zufallszahl $pos_x = 50; // links $pos_y = 10; // oben // Zeichne die Zufallszahl imageString($bild, 5, $pos_x, $pos_y, $zufallszahl, $farbe); // Sende "browser header" header("Content-Type: image/png"); // Sende das Bild zum Browser echo imagePNG($bild); // Lösche das Bild imageDestroy($bild);
<?php require_once "unicode.php"; $i = imageCreate(400, 400); //Функция imageCreate() - создает новое палитровое изображение возвращает идентификатор изображения(1-ширина изо, 2- высота изо) $color = imageColorAllocate($i, 0, 255, 0); imageFilledRectangle($i, 0, 0, imageSX($i), imageSY($i), $color); //Функция imageFilledRectangle() - рисование закрашенного прямоугольника (1-ресурс изображения, 2 - х-координата точки 1, 3 - у-координата точки 1, 4 - х-координата точки 2, 5 - у-координата точки 2, 6 - цвет заливки) $color = imageColorAllocate($i, 255, 0, 0); imageRectangle($i, 100, 100, 200, 200, $color); //Функция imageRectangle() - рисование прямоугольника (1-ресурс изображения, 2 - х-координата точки 1, 3 - у-координата точки 1, 4 - х-координата точки 2, 5 - у-координата точки 2, 6 - цвет бордера) imageSetThickness($i, 10); //Функция imageSetThickness() - задает толщину линии(1-ресурс изображения, 2-толщина линии) $color = imageColorAllocate($i, 0, 0, 255); imageRectangle($i, 50, 80, 150, 150, $color); imageSetThickness($i, 3); $color = imageColorAllocate($i, 255, 255, 0); imageLine($i, 10, 10, 350, 250, $color); //Функция imageLine() - рисует линию по двум точкам (1-ресурс изображения, 2 - х-координата точки 1, 3 - у-координата точки 1, 4 - х-координата точки 2, 5 - у-координата точки 2, 6 - цвет бордера) $color = imageColorAllocate($i, 255, 255, 255); imageArc($i, 300, 100, 150, 150, 0, 0, $color); //Функция imagearc() - рисует окружность дуги с заданными координатами центра, дуга рисуется по часовой стрелке (1-ресурс изображения, 2 - х-координата центра, 3 - у-координата центра, 4 - ширина дуги, 5 - высота дуги, 6 - угол начала дуги в градусах, 7 - угол окончания дуги в градусах, 8 - цвет дуги ) //Функция imagefilledarc() - рисует и заливает окружность дуги с заданными координатами центра, дуга рисуется по часовой стрелке (1-ресурс изображения, 2 - х-координата центра, 3 - у-координата центра, 4 - ширина дуги, 5 - высота дуги, 6 - угол начала дуги в градусах, 7 - угол окончания дуги в градусах, 8 - цвет дуги ) $color = imageColorAllocate($i, 0, 255, 255); imagefill($i, 130, 130, $color); //Функция imagefill() - производит заливку, начиная с заданных координат точки (1-ресурс изображения, 2 - х-координата точки, 3 - у-координата точки, 4 - цвет заливки, либо можно указать константу заливки IMG_COLOR_TILED) $im = imagecreatefromgif("images/image.gif"); imagesettile($i, $im); //Функция imagesettile() - задает изображение, которое будет использовано в качестве элемента мозаичной заливки (1-ресурс изображения который будут заливать, 2- ресурс изображения для использования мозайчной заливки) imagefill($i, 250, 50, IMG_COLOR_TILED); $color = imagecolorallocate($i, 0, 0, 0);
$colorIntellectual = imageColorAllocate($image, 0, 255, 0); // clear the image with the background color imageFilledRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $colorBackgr); // calculate start date for diagram and start drawing $nrSecondsPerDay = 60 * 60 * 24; $diagramDate = time() - $daysToShow / 2 * $nrSecondsPerDay + $nrSecondsPerDay; for ($i = 1; $i < $daysToShow; $i++) { $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");
/** * Draws a rectangle on the image * @param Point $leftTop Point of the upper left corner * @param Dimension $dimension Dimension of the rectangle * @param Color $color * @param integer $width * @return null */ public function drawRectangle(Point $leftTop, Dimension $dimension, Color $color, $width = 1) { $color = $this->allocateColor($color); $leftTopX = $leftTop->getX(); $leftTopY = $leftTop->getY(); $rightBottomX = $leftTopX + $dimension->getWidth(); $rightBottomY = $leftTopY + $dimension->getHeight(); for ($i = 1; $i <= $width; $i++) { imageRectangle($this->resource, $leftTopX, $leftTopY, $rightBottomX, $rightBottomY, $color); $leftTopX++; $leftTopY++; $rightBottomX--; $rightBottomY--; } }
function legend($im, $sz, $C) { $r = 30; $fn = 5; $x = $sz - (4 * $r + 7) - 2; $y = $sz - $r - 3; imageFilledRectangle($im, $x, $y, $x + 4 * $r + 7, $y + $r + 1, $C['dkgray']); imageRectangle($im, $x + 0 * $r + 1, $y + 1, $x + 1 * $r + 0, $y + $r, $C['red']); imageRectangle($im, $x + 1 * $r + 2, $y + 1, $x + 2 * $r + 2, $y + $r, $C['yellow']); imageRectangle($im, $x + 2 * $r + 4, $y + 1, $x + 3 * $r + 4, $y + $r, $C['darkgreen']); imageRectangle($im, $x + 4 * $r + 6, $y + 1, $x + 3 * $r + 6, $y + $r, $C['brightgreen']); imageString($im, $fn, $x + 3 + 0 * $r, $y + $r / 3, "<30", $C['red']); imageString($im, $fn, $x + 5 + 1 * $r, $y + $r / 3, "30+", $C['yellow']); imageString($im, $fn, $x + 7 + 2 * $r, $y + $r / 3, "35+", $C['darkgreen']); imageString($im, $fn, $x + 9 + 3 * $r, $y + $r / 3, "40+", $C['brightgreen']); }
public function make_img() { $this->image = imageCreate($this->width, $this->height); //创建图片 $this->backcolorRGB = $this->getcolor($this->backcolor); //将#ffffff格式的背景色转换成RGB格式 imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->backcolorRGB); //画一矩形 并填充 $this->size = $this->width / $this->len; //宽度除以字符数 = 每个字符需要的宽度 if ($this->size > $this->height) { $this->size = $this->height; } //如果 每个字符需要的宽度 大于图片高度 则 单字符宽度=高度(正方块) $this->sizestr2str = $this->size / 10; //以每个字符的1/10宽度为 字符间距 $left = ($this->width - $this->len * ($this->size + $this->sizestr2str)) / $this->size; // (验证码图片宽度 - 实际需要的宽度)/每个字符的宽度 = 距离左边的宽度 for ($i = 0; $i < 3; $i++) { //生成干扰线 $linecolor = imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255)); imageline($this->image, rand(0, 30), rand(0, 30), rand(30, 80), rand(0, 30), $linecolor); } $text = ''; for ($i = 0; $i < $this->len; $i++) { $randtext = rand(0, 9); //验证码数字 0-9随机数 $text .= $randtext; //写入session的数字 $textColor = imageColorAllocate($this->image, rand(50, 155), rand(50, 155), rand(50, 155)); //图片文字颜色 if (!isset($this->textsize)) { $this->textsize = rand($this->size - $this->size / 10, $this->size + $this->size / 10); } //如果未定义字体大小 则取随机大小 $location = $left + ($i * $this->size + $this->size / 10); imagettftext($this->image, $this->textsize, rand(-18, 18), $location, rand($this->size - $this->size / 10, $this->size + $this->size / 10), $textColor, $this->font, $randtext); //生成单个字体图象 } if (isset($this->noisenum)) { $this->setnoise(); } //杂点处理 if (isset($this->bordercolor)) { $this->bordercolorRGB = $this->getcolor($this->bordercolor); imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->bordercolorRGB); } return $text; }
//specify diagram parameters(these are global) $diagramWidth = ($curyear - 1975 + 1) * 24 + $hs; $diagramHeight = ($maxcats - 1) * $va + $vs; //create image $image = imageCreate($diagramWidth, $diagramHeight); //allocate all required colors $white = imageColorAllocate($image, 255, 255, 255); #$colorBackgr=imageColorAllocate($image,192,192,192); $colorBackgr = imageColorAllocate($image, 255, 255, 255); $black = imageColorAllocate($image, 0, 0, 0); $red = imageColorAllocate($image, 255, 0, 0); $green = imageColorAllocate($image, 0, 200, 370); //clear the image with the background color imageFilledRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $colorBackgr); //draw rectangle a round diagram (mark sits boundaries) imageRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $black); //print descriptive text into the diagram $today = date("Y-m-d"); imageString($image, 3, $diagramWidth / 3, 5, "HEC list entry population", $black); imageString($image, 3, $diagramWidth - 200, 5, "last update {$today}", $black); imageLine($image, 0, $vs - $va * 2, $diagramWidth - 1, $vs - $va * 2, $black); $j = -1; imageLine($image, 0, $j * $va + $vs, $diagramWidth - 1, $j * $va + $vs, $black); $j = 0; for ($j = 0; $j < $maxcats; $j++) { imageLine($image, 0, $j * $va + $vs, $diagramWidth - 1, $j * $va + $vs, $black); } $max = 0; $max2 = 0; $i = $hs; imageLine($image, $i, $vs - $va * 2, $i, $diagramHeight - 1, $black);
for ($y = 0; $y < $grid_y_inc; $y++) { if ($img_grid_random_color) { $r = rand($txt_rgb_min, $txt_rgb_max); $g = rand($txt_rgb_min, $txt_rgb_max); $b = rand($txt_rgb_min, $txt_rgb_max); $color = imageColorAllocate($img, $r, $g, $b); } else { $color = $black; } $yline = $yline + $grid_spacing; imageLine($img, 0, $yline, $img_width, $yline, $color); } } // Border if ($img_use_border) { imageRectangle($img, 0, 0, $img_width - 1, $img_height - 1, $black); } $string_len = strlen($string); $position = $txt_horizontal_pos; // Looping through each letter for ($i = 0; $i < $string_len; $i++) { $c = $string[$i]; // Angle if ($txt_use_angles) { $angle = rand($txt_letter_angle_min, $txt_letter_angle_max); } else { $angle = 0; } // Font if ($txt_use_random_font) { $font = $txt_font_dir . b1n_arrayRand($txt_fonts);