bonjour mon souci est pour l'affichage d'une image avec le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
<?php 
 
class Captcha {
 
    public function getImageBinary($security_code) {
        ob_start() ;
 
        //Set the image width and height 
        $width = 100; 
        $height = 20;  
 
        //Create the image resource 
        $image = ImageCreate($width, $height);  
 
        //We are making three colors, white, black and gray 
        $white = ImageColorAllocate($image, 255, 255, 255); 
        $black = ImageColorAllocate($image, 0, 0, 0); 
        $grey = ImageColorAllocate($image, 204, 204, 204); 
 
        //Make the background black 
        ImageFill($image, 0, 0, $black); 
 
        //Add randomly generated string in white to the image
        ImageString($image, 3, 30, 3, $security_code, $white); 
 
        //Throw in some lines to make it a little bit harder for any bots to break 
        ImageRectangle($image,0,0,$width-1,$height-1,$grey); 
        imageline($image, 0, $height/2, $width, $height/2, $grey); 
        imageline($image, $width/2, 0, $width/2, $height, $grey); 
 
        //Tell the browser what kind of file is come in 
        //header("Content-Type: image/jpeg"); 
 
        //Output the newly created image in jpeg format 
        ImageJpeg($image); 
 
        //Free up resources
        ImageDestroy($image); 
 
        return ob_get_clean();
    }
 
}
?>
code du controller :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 function form() { 
    //Let's generate a totally random string using md5 
    $md5_hash = md5(rand(0,999)); 
    //We don't need a 32 character long string so we trim it down to 5 
    $security_code = substr($md5_hash, 15, 5); 
    //Set the session to store the security code
    $_SESSION["security_code"] = $security_code;
 
    $captcha = new Captcha(); 
    $_SESSION["security_code_img"] = $captcha->getImageBinary($security_code);
 
  }
code de l'affichage :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
header("Content-type: image/jpeg");
echo '<img src="captcha_displayer" />';
 
ou même 
 
echo $_SESSION["security_code_img"];
résultat obtenu :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ��C	    $.' ",#(7),01444'9=82<.342��C	  2!!22222222222222222222222222222222222222222222222222��d"��	 ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B����	#3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?�����6�/֠�^�"�;��#K�UD���	���b���6O�*��S�����j7���+-��dy.C97'�������?��}#������?�/�7�Z�����U�+Z񦹪[��f��\�\>ȢK�2����d�xpS�����W�?��������D�Ŗ_��薊�e����͍v���6Ao��n�dP}^��:ZK��b�g�� P��[km�7e$�3��z�ظ�~"–ҧ�/%�m2 M�:�CL�Qd�VEW$cnN{g���L����h��[Y_E��f���|���͑�_ �/��jMkƞԵkK�}��_[�����V�n��yD�̌���cfl�.(V�����ۤ��WV�%ΨM� �-��31l1(�n ,�������#Wӡ��Եy!���:�P��>P̞Tl���:�����گ��1q�_^>� �j:-嵘��$�$̬H@ʐ����UPs��o�O{�E������ߚ�p���� ����!^x�?�K�M�C�����T�_�o��� �����oO��_H����~���?��}#������?�/�7�Z�����Q�	���b���6O�*���?��}#������?��������w����> �Wڧ�.��/nn�[�A%ĭ#��8�'����G���n�!w$�J/�Lv�!R|���ݎqҊ5/�~�5K�B{�Qe���p��31c���&������j���?�7E����j���?�7G�(���������tQ@�(���������t����j���?�7Ej��߇��젒�Tg	�2�ǒ�G����d?�*��(���������tQ@�(���������t����j���?�7E����j���?�7G�(���������tQ@��<)c��.]?O��X���M�+6⪽�� (����