Images into IJC

User 8a7878ec6d

30-05-2013 19:35:37

Hi,


I would like to add a rather large number of images (dose-response curves) to a database. I know I can do this through the URL fields, but I would rather have them directly stored in the database as binary fields. How can I accomplish this without having to add them one by one?


Thanks!

ChemAxon 2bdd02d1e5

31-05-2013 10:31:53

Hi, it's not possible in GUI. It might be done by groovy scripting, but I don't know if you are familiar with scripting IJC. Also we don't currently have such sample script in our scripting docs, but Insert or Update a Row script would be part of a more complex script.


Filip

User f67d4188b6

03-06-2013 09:06:41

We do exactly what describe using an external php script that matches terms in the image names to columns in the database, and then update a blob field with the binary image information.


As long as the images are png and less then 64kb this works fine.


 


The core of this script is these lines:


 


if(FALSE === ($image_file_contents = file_get_contents($image_file_path))){
                echo("\n Error ". __LINE__ ." opening $image_file_path \n");
                exit();
            }
if ($mysqli_stmt = mysqli_prepare($mysqli_link, "UPDATE $DB_TABLE SET $DB_IMAGE_FIELD=? WHERE $DB_ID_FIELD=?")) {
                
                if(!mysqli_stmt_bind_param($mysqli_stmt, "si", $image_file_contents, $row_id)){
                    printf("\n Error ". __LINE__ .": %s\n", mysqli_error($mysqli_link));
                    exit();
                }
                
                if(!mysqli_stmt_execute($mysqli_stmt)){
                    printf("\n Error ". __LINE__ .": %s\n", mysqli_error($mysqli_link));
                    exit();
                }
                
                
                /* close statement */
                mysqli_stmt_close($mysqli_stmt);
                
                rename($path.$image[0], $ACCEPTED_PATH.$image[0]);
                echo("processed and moved.\n");
            }else{
                printf("\n Error ". __LINE__ .": %s\n", mysqli_error($mysqli_link));
                exit();
            }


ChemAxon 2bdd02d1e5

03-06-2013 14:08:05

I did not try the php script, but is it true that all images are correctly uploaded to the database? What length the blob field has? 

User f67d4188b6

03-06-2013 14:31:43

The blob field is a standard BLOB field in our MySql database, those are 64kb.
As long as the images are png, it always works and instant jchem has no problem detecting the mime type and displaying the image in a form or grid view.
The images are generated by Prism by the way, and some of our experimental-results tables even have 2 blobs: one for the DRC curves with errorbars and another with the individual datapoints, so that you can see what Prism did.
Note that a gridview with 2000 images of 60kb each can take a while to go through the cable, as it is a lot of data.


 


It took some tweaking to get the script to work with all the different situations, so the complete script is ofcourse much larger.
What i do want to convey is that the principle works, you can put images in the database and use them in IJC.

User 8a7878ec6d

03-06-2013 15:42:54

Thanks for sharing your experience, Ellert.


While IJC is very strong on the chemistry side, it falls short when it comes to handling biological data such as dose-response curves. Even if you can import these as images, you cannot export them as far as I know.


Regards,


Evert

ChemAxon 2bdd02d1e5

04-06-2013 07:02:28

Yes, of course, this is a standard way how to put images into the database and use them in IJC.


Thanks


Filip