I have a MySQL database with a large number of images stored in it. I know how to retrieve these images and display them one at a time.

What I would like to do is write a script which collects the images, then saves the images to a directory on my server.

The problem I have encountered is that the data from the database all appears to be in JPEG binary format, so I can't figure out what to do, to be able to modify the images with GD, or even to save them using PHP code.

Do I need to convert these images first, or something else?

Any help would be appreciated!

    If you can read the data from the database, you can certainly just do:

    $query = 'QUERY FOR IMAGE FILES';
    
    $saveDir = '/path/to/save/directory/';
    
    while($row = mysql_fetch_assoc($result))
    {
        $fp = fopen('./tmp.jpg', 'w+');
        fwrite($fp, $row['image_data']);
        fclose($fp);
    
    $img = imagecreatefromjpeg('./tmp.jpg');
    
    // Modify them as you wish...
    
    // To save, do this:
    imagejpeg($img, $saveDir.$row['filename'].'.jpg', 80);
    }

    One of a few things you could do.

      Write a Reply...