+ Post New Thread
Results 1 to 3 of 3
Web Development Thread, PHP saving from MSSQL db Base64 image to jpg in Coding and Web Development; Hoping someone can help. We're running PAC's SecureNet software here and i'm trying to tie in a webcam, so that ...
  1. #1

    Join Date
    Jun 2013
    Posts
    22
    Thank Post
    4
    Thanked 6 Times in 4 Posts
    Rep Power
    3

    PHP saving from MSSQL db Base64 image to jpg

    Hoping someone can help. We're running PAC's SecureNet software here and i'm trying to tie in a webcam, so that when we take someone's photo, it is already inside the software. Using MS Server Management Studio I can see the photo field. The software currently saves the image as Base64.

    For our own systems it would be really handy to have access to these images. So I've got a PHP script which can see the PAC database and extra the photo code. I can display this easily enough, although I barely understand it.

    My problem comes when I try to save the file. It saves a typically 120kb jpg as a 900kb jpg. And it's a jpeg which Word can use but can't be opened in Photoshop?

    We're about to hand out 300 photo IDs to our sixth form, so I'm trying to streamline this process as much as possible. Here's my code:
    PHP Code:
    $data "data:image/jpeg;base64,".base64_encode($temp_photo);
    list(
    $type$data) = explode(';'$data);
    list(, 
    $data)      = explode(','$data);
    $data base64_decode($data);

    $success file_put_contents($output_file$data); 
    I've tried using imagecreatefromstring() but I can't seem to pass the correct data. Does anyone have any idea what I'm doing wrong?

  2. #2

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,800
    Thank Post
    110
    Thanked 582 Times in 503 Posts
    Blog Entries
    1
    Rep Power
    223
    Little bit rough but:

    PHP Code:
    $img imagecreatefromstring(base64_decode($data));  

    if(
    $img !== false)  
    {
        
    imagejpg($img,$output_file);  
        
    imagedestroy($img);   


  3. #3

    Join Date
    Jun 2013
    Posts
    22
    Thank Post
    4
    Thanked 6 Times in 4 Posts
    Rep Power
    3
    Thanks Geoff,

    I've tried your variation and got no where. In the end, I changed the code to save the image as a bmp:
    PHP Code:
    $data "data:image/wbmp;base64,".base64_encode($temp_photo); 
    Which Photoshop at least allows for import. From there I'm just going to run an action to save the files as jpegs. Utterly annoying and bizarre, but at least it is a relatively efficient workflow.

    Graham

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 3
    Last Post: 12th May 2013, 06:50 PM
  2. Replies: 6
    Last Post: 22nd January 2013, 04:51 PM
  3. [Fog] Image to & from local USB HDD with FOG - is it possible?
    By mark in forum O/S Deployment
    Replies: 5
    Last Post: 19th January 2011, 08:48 PM
  4. Replies: 6
    Last Post: 7th April 2010, 09:46 AM
  5. Autocreate AD accounts from MSSQL
    By CyberNerd in forum Coding
    Replies: 9
    Last Post: 12th July 2006, 03:00 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •