За последние 24 часа нас посетили 20067 программистов и 1586 роботов. Сейчас ищут 1847 программистов ...

Php. Как вставить фото в генератор?

Тема в разделе "Сделайте за меня", создана пользователем troling, 12 мар 2017.

Метки:
  1. troling

    troling Новичок

    С нами с:
    21 фев 2017
    Сообщения:
    7
    Симпатии:
    0
    PHP:
    1. <?php
    2. $key = $_GET['q'];
    3. if ($key == '') {
    4. //$key = urlencode('test');
    5. //print ' ';
    6. }
    7. ?>
    8. <?php
    9. $q2 = $key;
    10. $q2s = str_replace('+', ' ', $q2s);
    11.  
    12. //You can do any necessary settings as you wish here
    13. //If you reduce the width and height of the captcha here then you have to change it in the css file as well
    14. $image_width = 600;
    15. $image_height = 500;
    16. $characters_on_image = 10;
    17. $font = 'images/monofont.ttf';
    18.  
    19. //The characters that can be used in the CAPTCHA code. Avoid confusing characters (l 1 and i for example)
    20. $possible_letters = "".$key."";
    21. $random_dots = 0;
    22. $random_lines = 20;
    23. $random_imgs = 1;
    24. $captcha_text_color="0x142864";
    25. $captcha_noice_color = "0x142864";
    26.  
    27. $code = '';
    28. $code = $key;
    29. //$i = 0;
    30. //while ($i < $characters_on_image)
    31. //{
    32. //    $code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
    33. //    $i++;
    34. //}
    35. $font_size = $image_height * 0.04;
    36. $image = @imagecreate($image_width, $image_height);
    37.  
    38.  
    39. /*Setting the background, text and noise colours here */
    40. $background_color = imagecolorallocate($image, 255, 255, 255);
    41.  
    42. $arr_text_color = RGB_HEX($captcha_text_color);
    43. $text_color = imagecolorallocate($image, $arr_text_color['red'],
    44. $arr_text_color['green'], $arr_text_color['blue']);
    45. $arr_noice_color = RGB_HEX($captcha_noice_color);
    46. $image_noise_color = imagecolorallocate($image, $arr_noice_color['red'],
    47. $arr_noice_color['green'], $arr_noice_color['blue']);
    48.  
    49. /*This generates the dots randomly strings in background */
    50. for( $i=0; $i<$random_dots; $i++ )
    51. {
    52.     imagefilledellipse($image, mt_rand(0,$image_width),
    53.      mt_rand(0,$image_height), 2, 3, $image_noise_color);
    54. }
    55.  
    56.  
    57. for( $i=0; $i<$random_imgs; $i++ )
    58. {
    59.  
    60. $green = imagecolorallocate($image, 0, 255, 0);
    61.  
    62.  
    63. imageellipse($image, 250, 250, 300, 200, $green);
    64.  
    65.  
    66. }
    67.  
    68. /*This generates lines randomly strings in background of image */
    69. for( $i=0; $i<$random_lines; $i++ )
    70. {
    71.     imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
    72.      mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
    73. }
    74.  
    75. /*This creates a text box and add 6 letters code in it */
    76. $textbox = imagettfbbox($font_size, 0, $font, $code);
    77. $x = ($image_width - $textbox[4])/10;
    78. $y = ($image_height - $textbox[5])/10;
    79. imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);
    80.  
    81. /* Show captcha image in the page html page */
    82. header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
    83. imagejpeg($image);//showing the image
    84. imagedestroy($image);//destroying the image instance
    85. $_SESSION['vpb_captcha_code'] = $code;
    86.  
    87. function RGB_HEX ($hexstr)
    88. {
    89.     $int = hexdec($hexstr);
    90.     return array("red" => 0xFF & ($int >> 0x10),"green" => 0xFF & ($int >> 0x8),"blue" => 0xFF & $int);
    91. }
    92. ?>
    Получается так
    [​IMG]
    P.S. Хочу чтобы за место круга грузилось рандомное фото из папки.
    Пожалуйста помогите реализовать - очень надо.
     
    #1 troling, 12 мар 2017
    Последнее редактирование модератором: 12 мар 2017
  2. MouseZver

    MouseZver Суперстар

    С нами с:
    1 апр 2013
    Сообщения:
    7.799
    Симпатии:
    1.331
    Адрес:
    Лень
    Мой 2013 рандом, криво но для "сделай за меня" сойдет
    PHP:
    1. <?php
    2. $resurse = rand(1,count(array_merge(glob("*.png"))));
    3. $resurse_d = rand(1,count(array_merge(glob("d/*.png"))));
    4. $resurse_n = rand(1,count(array_merge(glob("n/*.png"))));
    5. $resurse_n_s = rand(1,count(array_merge(glob("n/s/*.png"))));
    6. IF($resurse == '1'){
    7. $img_1 = imageCreateFromPNG("1.png");
    8. $img_2 = imageCreateFromPNG("d/$resurse_d.png");
    9. } elseIF($resurse == '2'){
    10. $img_1 = imageCreateFromPNG("2.png");
    11. $img_2 = imageCreateFromPNG("n/$resurse_n.png");
    12. $img_3 = imageCreateFromPNG("n/s/$resurse_n_s.png");
    13. } elseIF($resurse == '3'){
    14. $img_1 = imageCreateFromPNG("3.png");
    15. IF(rand(1,2) == '1'){
    16. $img_2 = imageCreateFromPNG("d/$resurse_d.png");
    17. } else {
    18. $img_2 = imageCreateFromPNG("n/$resurse_n.png");
    19. }
    20. IF($resurse = rand(1,2) == '2'){
    21. $img_3 = imageCreateFromPNG("n/s/$resurse_n_s.png");
    22. }
    23. }
    24. header("Content-type: image/png");
    25. header("Content-Disposition: filename=".rand(000000,9999999999).";");
    26. imagecopy($img_1,$img_2,0,0,0,0,46,64);
    27. IF($resurse == '2'){
    28. imagecopy($img_1,$img_3,0,0,0,0,46,64);
    29. }
    30. imagealphablending($img_1, false);
    31. imagesavealpha($img_1, true);
    32. imagepng($img_1);
     
  3. troling

    troling Новичок

    С нами с:
    21 фев 2017
    Сообщения:
    7
    Симпатии:
    0
    Ерунда какая-то! Еще может варианты будут внедренные в код... Я же помощи прошу! =)
     
  4. troling

    troling Новичок

    С нами с:
    21 фев 2017
    Сообщения:
    7
    Симпатии:
    0
    поможет кто нить?
     
  5. denis01

    denis01 Суперстар
    Команда форума Модератор

    С нами с:
    9 дек 2014
    Сообщения:
    12.227
    Симпатии:
    1.714
    Адрес:
    Молдова, г.Кишинёв
    @troling надо ждать, может кто найдётся и поможет
     
  6. MouseZver

    MouseZver Суперстар

    С нами с:
    1 апр 2013
    Сообщения:
    7.799
    Симпатии:
    1.331
    Адрес:
    Лень
    PHP:
    1. $G = glob( "путь_к_папки/*.png" );
    2. $G[array_rand ( $G, 1 )];
    вот он рандом
     
    denis01 нравится это.