Some images are more corrupt than others
Tuesday, August 10th, 2010
Today I tried to make a Visual FoxPro report with images of teachers and students. I did not want to store the images in tables, neither did I want to store their file names in tables. All I wanted was to use the images as they were stored in a folder on the hard disk.
As I did not get it to work I posted a cry for help here.
I use vfp9 sp2 and winxp.
The cursor for the report has two field: id and lastname.
SELECT id, lastname FROM teachers02 INTO CURSOR cur_temp SELECT cur_temp SET SYSMENU OFF npages = 10 REPORT FORM report1 TO PRINTER PROMPT PREVIEW Range 1, npages SET SYSMENU ONIn a folder I have images of the teachers named id.jpg, so the teacher with id = 3 has image 3.jpg.
In the detail band I have a textbox for the id, a textbox for the lastname, and a Picture/Ole control for the image. For the image;s control source property I have: MYUDF().
PROCEDURE MYUDF() LOCAL cid cid = ALLTRIM(STR((cur_temp.id))) MESSAGEBOX(cid) ** image path LOCAL imgpath imgpath = app_path + 'images\'+cid+'.jpg' ** check if image exists IF ADIR(arr_temp,imgpath) = 0 MESSAGEBOX(imgpath + " does not exist") imgpath = app_path + 'images\7xx.jpg' ELSE MESSAGEBOX(imgpath + " does exist") ENDIF && imgpath = app_path + 'images\7xx.jpg' MESSAGEBOX(imgpath) RETURN imgpathIf the image does not exist the image 7xx.jpg will be shown.
I have stepped through the MYUDF and it behaves as it should, i.e. till it has executed for the first page. cid is 1, 3, and 4, and it finds out correctly if 1.jpg, 3.jpg, and 4.jpg exists or not, and the correct imgpath is returned.
However, after it has run for the first page (three images) it displays the error: Picture too big, corrupt or in wrong format.’
If I change the last lines of MYUDF to:
imgpath = app_path + 'images\7xx.jpg' MESSAGEBOX(imgpath) RETURN imgpathit works perfectly, i.e. if one is happy with showing the same picture for all the teachers.
![]()
What am I doing wrong?
Due to Internet searches and intensive trying and failing, I found the solution. I discovered that corrupt files can be mad OK with a little bit of careful attention.
Searching the Internet I found a workaround.
Using the free IrfanView – File – Batch Conversion/Rename… I checked Batch conversion, set JPG as output format and in Options for output format unchecked all the check boxes (from what Internet told me the EXIF data should be removed). I used as input files my folder of jpg images, set Files of type to JPG and clicked Add all to have the input files ready. Four output directory I chose an empty folder. Then I clicked Start Batch and all jpgs that before was vfp-corrupt were now accepted.
Problem solved!
My udf is now simply:
PROCEDURE MYUDF()
LOCAL cid as string
cid = ALLTRIM(STR(cur_temp.id))
LOCAL imgpath as string
imgpath = app_path + ‘images\’ + cid + ‘.jpg’
** check if image exists
IF ADIR(arr_temp,imgpath) = 0
imgpath = app_path + ‘images\missing.bmp’
ENDIF
RETURN imgpath



