Gregwar / Captcha

PHP Captcha library
MIT License
1.73k stars 290 forks source link

Blank image #77

Closed venkytt closed 4 years ago

venkytt commented 4 years ago

Hello guys

Autoload installed via composer... all is well. I also created a temp directory, writable in the same directory where the files of captcha are.

The result is a blank image :-(

The code is

    $builder = new CaptchaBuilder;
    $builder->build();
    echo "<pre>"; print_r($builder); echo "</pre>"; exit;
    header('Content-type: image/jpeg');
    $builder->output();
    exit;

When i uncomment the line starting with "echo", i get a blank image and the result of the print_r (the echo line) is as follows:

What am I doing wrong?

Gregwar\Captcha\CaptchaBuilder Object
(
    [fingerprint:protected] => Array
        (
            [0] => 0
            [1] => 207
            [2] => 221
            [3] => 228
            [4] => 2
            [5] => 253
            [6] => 155
            [7] => 239
            [8] => 0
            [9] => 26
            [10] => 20
            [11] => 97
            [12] => 32
            [13] => 3
            [14] => 240
            [15] => 154
            [16] => 163
            [17] => 1
            [18] => 14
            [19] => 39
            [20] => 145
            [21] => 9
            [22] => 2
            [23] => 1
            [24] => 61
            [25] => 56
            [26] => 69
            [27] => 8
            [28] => 5
            [29] => -3
            [30] => 2
            [31] => 0
            [32] => 0
            [33] => 4
            [34] => 2
            [35] => -6
            [36] => -4
            [37] => 3
            [38] => 0
            [39] => 4
            [40] => 1
            [41] => 77
            [42] => 37
            [43] => 3
            [44] => 0
            [45] => 107
            [46] => 14
            [47] => 45
            [48] => 29
            [49] => 3
            [50] => 1
            [51] => 65
            [52] => 19
            [53] => 79
            [54] => 13
            [55] => 1
            [56] => 121
            [57] => 28
            [58] => 7
            [59] => 46
            [60] => 0
            [61] => 0
            [62] => -6
            [63] => 3
        )

    [useFingerprint:protected] => 
    [textColor:protected] => Array
        (
        )

    [backgroundColor:protected] => 
    [backgroundImages:protected] => Array
        (
        )

    [contents:protected] => Resource id #3
    [phrase:protected] => 3jfj9
    [builder:protected] => Gregwar\Captcha\PhraseBuilder Object
        (
            [length] => 5
            [charset] => abcdefghijklmnpqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
        )

    [distortion:protected] => 1
    [maxFrontLines:protected] => 
    [maxBehindLines:protected] => 
    [maxAngle:protected] => 8
    [maxOffset:protected] => 5
    [interpolation:protected] => 1
    [ignoreAllEffects:protected] => 
    [allowedBackgroundImageTypes:protected] => Array
        (
            [0] => image/png
            [1] => image/jpeg
            [2] => image/gif
        )

    [tempDir] => temp/
    [background] => 13622756
)
Gregwar commented 4 years ago

Do you have any warning appearing? (Check your logs) Do you have php-gd library installed?

venkytt commented 4 years ago

Hi

Thanks for the prompt response!

Yes, GD is present. phpinfo confirms it, and it is enabled.

No, no errors/warnings in the logs. Error reporting is being logged... but no errors from the above scripts nor from the autoload included files

Do you see anything missing or incorrect in the above print_r result please? Is it what you are expecting?

Thanks again

Gregwar commented 4 years ago

Does it works if you use save('out.jpg') instead of output() ?

venkytt commented 4 years ago

On the following code,

ini_set('display_errors', 1); 
error_reporting(E_ALL);
include_once("vendor/autoload.php");
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
$phraseBuilder = new PhraseBuilder(5, '0123456789');
$captcha = new CaptchaBuilder(null, $phraseBuilder);
$captcha->build();
    //header('Content-type: image/jpeg');
    $captcha->output();

Note: i have left out the header stuff just to see what i get...

����JFIF``��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ��C     ��C   ��(�"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������� ?����+�� (�� ���xxkϢj)��56��[' 1��l׿~�?���6�� �d�O�~+N��|��]F�<�ePc�'��*]�_���1�n|���<�������-#G��Q��$��ۡg��@��}9�o�����2��\�%�ԭ|���c����H���� �vO��%?dϏ��gO��\������>A��K�9��£u����e��;��_�_�5�[�&���n����u uo �XɊY���ǖ��k[��(���j(���?0��#�]�τ�'����x_M����´�H��3̲�b/R ��zj�>���߱7���r sN���O��so���a�+�ی��φ��������w�����"��rh��ʈ�o1���l��n����?k߈���o���F��#C�-���R�Y�bIߒ�gqԔ�9��9(Ӷ����Ş ������M�AԐn6����&ܐ*ppG�gi�mޱ����׳��kh̒HǢ��I>¿E��F��������ě;9<_���3^�����'�T ���n v�|m]�4d�h�~�~%��z~��{���|Yd��G�$(�Y�<�1�����v�8̶���W �-���X��'���˩xĶ)y:[[�����3��s��z���ψ���?����A�� \h:f�"�ln�J\�$ �.�i�2� ��W����LZ|ֵ�'F��ּ)��?u���d[Ayv\��"l��@���ď�H�%����ٵ��(�h�D��� � H��y�|���� ���|O�N����Q�j��g��Mʻ�P� 0� #�M}�9�����!�kZ��^'���+C��}2]���<|���e��I#p��N}<���.� �8�I?x�����d�w�oxV)>�&��ϧ#����?�+���)�<5��ᗃm�h��ƍ�V(DC?��˾~�����x���f�����/���Ld�|�@m��I��e��=+���+�P���E�[�7~ M��Ҭ�7��T{�\���n�L�6r�ץJ�ҵ���?�5��<�?:>|1��O[xk���7w��eq#$��%~���=$�F�gx��<�O�� xH��|w~�s���n���H� ?.rı�O��g�S���f�g��to��^j��G�u� �Ubd=77�t1��/����y/��}v�\�֒�}}$�l�V}�ȥC� �������n�U�E������&�yUMI���[Ƕ��&���'�» /�;}ol�Sqgl#�:L�]��c����?b� ��v���Um?��pֱ-��$�*33�\H�lc$�|��W�߾,�����o�z��o�xb�U�`4���ғ@�b �s�h��L��1���C�~��j+�/!�O]��N9��NfrI�}Ӕ];�+��~��B�Q�Z������?g� �� ����msƾ&��m�8����ʦU�����#��<�O�=�� �����<#����4��W� >B�7���o��˱s��_!_~��mZ������-�ȴ1�G"��WX�C�sq޾����O����m��ū?�&�(� K���̊��R0q"�n��0Ҝ���N��(?�]�o� �N�&���� ��9�4k]2��X.t�{}:��H��,�Q�.FA��]���i�u�~�� 6�^��Y�1;H�F��[a�c=O0�=[���S�3�7]��;=CY��� ��܋��T�\��b 8c�rŽj�7+.����mN�m���}t?mO�>Ky��;�I�t���j��v�a$�D*�I�r�]۹�O���R|G�����tɥ�#I�e���Nު�ɍ�B�rpFMy5&���QE#P����ú��|1c����,Ѿx+P��}?U���� �%T�P.���3~��QW��9�NP�Gf?g��c�����|w��5k����H�M���JR)�;�<Ȝ�*��/�me��C����-Zɶ�\j1°L�0�1� �U��G@QXFi�&�?�3����=�F��>�!��c���ψ���o�]X��vâ5�Y��{��=zW���^9��&�� &[ˁ-�7���첕U@{�Kz0�%p���Ƅ#���~.���߈g(�N��1lX�5mB[�ln��1ۜ ��zW�~�2|'��T���`

Gregwar commented 4 years ago

Ok so you are indeed getting a jpeg file but the content of the file itself is blank

venkytt commented 4 years ago

ou use save('out.jpg') i

Yes!!! Save works!!!

Hmmm.... the "temp/" directory: where does it have to be? Does it have to be in /vendor/gregwar/captcha/ ?

I suspect a permission issue

Gregwar commented 4 years ago

Are you using linux or windows?

Gregwar commented 4 years ago

(Check for trailing spaces ` before the PHP tag as well <?php`, this can output an actual space and corrupt the jpg file)

venkytt commented 4 years ago

GRRRRR... that was the culprit...

works well...

it'd be nice to have the usual php error of headers sent already...

Gregwar commented 4 years ago

Yes I would like to have it always by default as well :smile: