[Gambas-user] How to convert blob to png file

Richard Terry rterry at ...1823...
Fri Aug 24 00:03:55 CEST 2012


Bill-Lancaster wrote:
> I have a database containing thumbnail images in a type blob field (mysql).
> Can someone help me to convert these to .png type files on disk?
> Thanks
>   
Bill, this may/may not work for you, I'm using postgres, It's probably 
crap code as I'm not much of a programmer, but this is what I use. If 
you were smart there is probably a one-liner - maybe whoever replies 
with a real solution I can update my code!


Public Function Image_get(pk_image As Integer, Optional bHas_MD5Sum As 
Boolean = False) As String
   
'--------------------------------------------------------------------------------------------------------------------------------------------
   'Gets an image from the backend returns the filename
   'pk_image = key to the blobs.images table
   'all progress note/procedures images will have an md5sum, not so 
patient pictures
   
'--------------------------------------------------------------------------------------------------------------------------------------------  

   Dim $Result As Result
   Dim tempFile As String
   Dim tempPicture As Variant
   Dim sql As String = "Select * from blobs.images WHERE pk=" & pk_image
  
   If bHas_MD5Sum Then
      sql &= "  AND md5sum is not null"
   Endif
   $Result = modDBConnect.exec_query(sql) '** YOU WON'T USE THIS - USE 
YOUR OWN CODE
   If $Result.count Then
      tempFile = Temp() & ".png"
      tempPicture = $Result!image
      If tempPicture.data Then
         File.Save(tempFile, tempPicture.data)
      End If
   End If
   Return tempFile
  
End

REgards

richard





More information about the User mailing list