Partager via


Create thumbnails of all your digital photos in a single table

At least once a week I download my photos to a new folder on one of my computers. As part of that process I run some code that generates thumbnail images into a table. With almost 22,000 pictures, the thumbnail table is almost 100 megabytes (1 Meg for the DBF, and 99 Meg for the FPT). The code below will create the thumbnail table if it doesn’t exist, or add to it only the missing ones if it does. MyPix.dbf is a table with just a few fields: the fullpath of the picture/video, a datetime stamp and a text field for an annotation. I keep these 2 tables separate because mypix.dbf is tiny (about the size of 3 JPGs) making it easy to backup and copy to other machines, whereas the thumbnail table is easily recreateable and thus discardable.

It’s pretty nice to be able to see all the pictures of my daughter (or any other string search using SQL Select) in proof sheets of thumbnails, and be able to scroll quickly around from her ultrasound 9 years ago to the most recent photos a few hours old. Each image has a tooltip which shows the text description (from the Mypix.dbf table). These thumbnail previews are available to me in either a VFP front end rich client or as a web application so I can query my photo database from any online machine in the world.

The code uses the new (in VFP9) GDIPlus Foundation class to make a thumbnail image. (see also this paper) and new VFP9 SQL enhancements. The table has only 2 fields: the full path to the picture and the thumbnail as a blob.

Notice :

  • the CAST function below which takes the binary representation of the thumbnail and converts it to a blob which is then inserted into the table.

  • The INSERT INTO …SELECT …FROM WHERE …NOT IN (SELECT … FROM ) command. Very powerful! The “WHERE..NOT IN” part inserts only those that are not already in the table.

  • There are 2 AS clauses: the “as blob” means the datatype Blob. The “as Thumb” is the name to give the resulting field.

  • Being able to call functions from within a SQL Select statement is very powerful.

My Canon camera records a “THM” file with every AVI movie file, which is just a JPG thumbnail, which is inserted into the blob field.

PROCEDURE MakeThumbDbf

      ?"now make thumbs"

      picpath=”e:\pictures\”

      SET CLASSLIB TO HOME()+"ffc\_gdiplus"

      IF !FILE("pixthumb.dbf")

            SELECT mypix.fullname,CAST(MakeThumb(PICPATH+ALLTRIM(mypix.fullname)) as blob) as thumb ;

                  FROM mypix.dbf ;

                  INTO table pixthumb

            INDEX on fullname TAG fullname

      ELSE

            INSERT INTO pixthumb ;

                  SELECT mypix.fullname,CAST(MakeThumb(PICPATH+ALLTRIM(mypix.fullname)) as blob) as thumb ;

      FROM mypix WHERE fullname NOT in (SELECT fullname FROM pixthumb)

      ENDIF

PROCEDURE makethumb(cFileName as String)

      LOCAL oImage as gpimage OF HOME()+"ffc\_gdiplus",oThumb as gpimage

      IF UPPER(JUSTEXT(cFileName))$"JPG"

            oImage=CREATEOBJECT("gpimage",cFileName)

            IF VARTYPE(oImage)='O'

                  oThumb=oImage.GetThumbnailImage(0,0)

                  IF mypix.rotate>0

                        oImage.RotateFlip(mypix.rotate)

                  ENDIF

                  oThumb.SaveToFile("d:\thumb.jpg","image/jpeg")

                  RETURN FILETOSTR("d:\thumb.jpg")

            ENDIF

      ELSE

            IF FILE(FORCEEXT(cFileName,"THM"))

                  RETURN FILETOSTR(FORCEEXT(cFileName,"THM"))

            ENDIF

      ENDIF

      RETURN ""

See also Sharing Disneyland Digital pictures

Comments

  • Anonymous
    August 10, 2005
    Thank you so much! I take pictures too and creating thumbnails is easily my least favorite part. I do have one problem with the code though:<br><br>oImage=CREATEOBJECT("gpimage",cFileName)<br><br> I get the error "Class Definition GPIMAGE is not found."<br><br>HOME()+"ffc_gdiplus" is pointing to the right place and there is a _gdiplus.vcx & _gdiplus.vct and when I view them there is a gpimage defined. Other than that, I don't know what I could be doing wrong.

  • Anonymous
    August 10, 2005
    What happens when you try to instantiate the class directly in the command window?
    oImage=NEWOBJECT("gpimage",HOME()+"ffc_gdiplus")
    Now i get intellisense on oImage.

  • Anonymous
    August 10, 2005
    That works for me and I get intellisense also.
    One more thing that I had to do was CreateFromFile. Here's what mine looks like now.

    ...
    *oImage=CREATEOBJECT("gpimage",cFileName)
    oImage=Newobject('GpImage',Home(1)+'ffc/_gdiplus.vcx')
    IF VARTYPE(oImage)='O'
    oImage.CreateFromFile(cFileName)
    oThumb=oImage.GetThumbnailImage(0,0)
    ...

    That is really neat and thank you a lot for the example. This is going to save me so much time!

  • Anonymous
    February 17, 2006
    &amp;nbsp;
    Programs need to read and write data. Sometimes the data storage is only used temporarily. If...

  • Anonymous
    March 17, 2006
    I like my Cingular 2125 SmartPhone (see Windows SmartPhone can run my Web Apps).
    &amp;nbsp;
    I went to Microsoft...

  • Anonymous
    March 21, 2006
    very informative site with lots of useful info

  • Anonymous
    June 04, 2006
    i like your website very much but please do get us more information about it

  • Anonymous
    August 22, 2006
    My prior post showed how to use an array of PictureBox controls to display multiple photographs on a...

  • Anonymous
    January 15, 2007
    I have already enjoy your website, and it is so nice and cool. I will visit your website again. Thank you.

  • Anonymous
    February 07, 2007
    I have already enjoy your website, and it is so nice and cool. I will visit your website again. Thank you.

  • Anonymous
    September 11, 2007
    Typically, a web site might show some pictures. These could be pictures of items for sale from a catalog,

  • Anonymous
    October 11, 2007
    PingBack from http://foxpro.ntsl119.com/scr/archives/505

  • Anonymous
    January 20, 2009
    PingBack from http://www.hilpers-esp.com/316747-visualizar-imagenes

  • Anonymous
    June 28, 2009
    Calvin, I want to use my Canon Ixus 50 camera as a mediaplayer; I have avi's I want to put on it but without the required thm-file. Do I need to make thm-files with your program or is there an easier way (program) to do this.(I am a mechanical engineer!)