• charltoncolin7

    (@charltoncolin7)


    I am having difficulty displaying the image I have put in my database.
    I am confident the image is there. Through phpmyadmin I can see the Image field is occupied. When I retrieve the image I can see a stream of character which have PNG near the start.

    I am using the following code to display the image in a test situation. (I have hard wired the row containing the information).
    Could any one let me know what I’m doing wrong. (I’m writing this as a volunteer supporting an orphanage in India).

    function test_image()
    {
    global $wpdb;

    $student_id = 77;

    $command = “Select Students.Image FROM Students WHERE Students.Student_id = “.$student_id;
    $rows = mysql_query($command);
    $rows = $wpdb->get_results($command, OBJECT);
    echo “rows = “.$rows.”
    “;

    foreach ($rows as $row):
    echo ‘<img src=”data:image/jpeg;base64,’.base64_encode( $row[‘image’] ).'”/>’;
    endforeach;
    }

    The output I get is

    Test Image

    rows = Array

    and then it blows up!

    When I var_dump $rows the image is present. I see it as a stream of characters and it has PNG near the start. I have tested it with both PNG and JPEG images the same result. I have also tried the code below but get the same result. Assistance would be greatly appreciated.

    Thanks

    ——————————————————————–

    function test_image()
    {
    global $wpdb;

    $student_id = 77;

    $command = “Select Students.Image FROM Students WHERE Students.Student_id = “.$student_id;
    $rows = mysql_query($command);
    $rows = $wpdb->get_results($command, OBJECT);

    foreach ($rows as $row):
    echo ‘<img src=”data:image/jpeg;base64,’.base64_encode( $row[‘image’] ).'”/>’;
    /*
    $data = base64_decode($row[‘Image’]);
    $im = imagecreatefromstring($data);
    if ($im !== false)
    {
    echo “Not False”;
    header(‘Content-Type: image/png’);
    imagepng($im);
    imagedestroy($im);
    }
    else echo “Is False”;
    endforeach;
    }

The topic ‘Displaying an image blob’ is closed to new replies.