как в php вставить картинку



Как вставить картинку в php

Автор Vasia xD задал вопрос в разделе Другие языки и технологии

Как вставить картинку php и получил лучший ответ

Ответ от Demoniqus[гуру]
Вот автоматическая генерация картинки. На стороне клиента просто в атрибут src присваивается адрес до этого php-скрипта. Изучай: <?php session_start(); Header("Content-type: image/png"); class captcha { public $capt = ''; private $fonts = array ("Primitive.ttf", "FLUBBER_.TTF", "grease__.ttf"); public function __construct($text) { if (preg_replace("/\\s+/", "", $text) != '') $this->paint_text($text); } public function get_new_captcha_text () { $i = rand (5,7); $captcha_text = ''; $symbols = array ( 0 => array (48, 57), 1 => array (65, 90), 2 => array (97, 122) ); while ($i > 0) { $x = rand(0,2); $symb = rand ($symbols[$x][0], $symbols[$x][1]); $captcha_text .= chr($symb); $i--; } return $captcha_text; } private function paint_text ($text) { $captcha = imageCreate(170, 40); $this->capt = $captcha; $bgcolor = imagecolorallocate($captcha, 255, 255, 255); imagefilledrectangle($this->capt, 0, 0, imageSX($this->capt), imageSY($this->capt), $bgcolor); $length = strlen($text) - 1; $i = 0; $font = rand(0,2); $font = realpath ('../fonts/' . $this->fonts[$font]); while ($i <= $length) { $r = rand (0, 200); $g = rand (0, 180); $b = rand (0, 200); $c = imagecolorallocate($this->capt, $r, $g, $b); $left = $i * 22; imagettftext($this->capt, 17, 0, $left, 25, $c, $font, $text[$i]); $i++; } $this->captcha_background(); } private function captcha_background () { $count_figures = rand (3, 9); while ($count_figures >= 0) { $type_figure = rand (0, 2); $r = rand (0, 240); $g = rand (0, 240); $b = rand (0, 240); $c = imagecolorallocate($this->capt, $r, $g, $b); switch ($type_figure) { case '0' : $angle = rand(0,1); if ($angle) { imageline($this->capt, rand(0, 30), rand(0, 3), rand(100,169), rand(27, 39), $c); } else { imageline($this->capt, rand(0, 30), rand(27, 39), rand(100,169), rand(0, 3), $c); } break; case '1' : imagerectangle($this->capt, rand(0, 50), rand(0, 12), rand(70,169), rand(14, 39), $c); break; case '2' : $count_points = rand(5, 9); $points = array (); $i = 0; while ($i < $count_points) { $points[$i * 2] = rand (0, 170); $points[$i * 2 + 1] = rand (0, 40); $i++; } imagepolygon($this->capt, $points, $count_points, $c); $count_figures--; break; } $count_figures--; } } } if (isset($_SESSION['captcha_text'])) { $text = $_SESSION['captcha_text']; $text = trim($text); $captcha = new captcha($text); imagePng($captcha-> capt); imagedestroy($captcha->capt); } else { exit(); } ?>

Ответ от 3 ответа[гуру]
Привет! Вот подборка тем с похожими вопросами и ответами на Ваш вопрос: Как вставить картинку php
 

Ответить на вопрос:

Имя*

E-mail:*

Текст ответа:*
Проверочный код(введите 22):*