1

Trying to troubleshoot someone else's not-so-great code. Any ideas would be greatly appreciated. It seems to bomb out at the <cfif> that brings in the image:

<cfif LEN(qryCampers.std_image_filename[iRow + iCol]) GT 0>

If I comment out that if (and only keep the section related to the "no_image.gif" out of the cfif statement) we're good. The document appears.

CF Server 8, SQL Server 2000, Images are relatively small in size (all under 30kb, no more than 300px in width), this code works some of the time and when it does, it takes FOREVER to load the PDF. This particular query (only 12 records) is causing the error.

The Error:

Invalid image format


The error occurred in D:\apps\Websites\Example\app\reports\dsp_camper_cards_preview.cfm: line 51
49 :                            <td width="40%" align="center" valign="middle">
50 :                                <cfif LEN(qryCampers.std_image_filename[iRow + iCol]) GT 0>
51 :                                    <cfimage source="../photos/#qryCampers.std_image_filename[iRow + iCol]#" action="read" name="cardImage">
52 :                                    <cfif cardImage.height GT cardImage.width>
53 :                                        <img src="../photos/#qryCampers.std_image_filename[iRow + iCol]#" height="150">

The cfdocument Code:

<cfdocument filename="#fileName#" format="PDF" pagetype="letter" 
    margintop=".175" marginbottom=".125" marginright=".125" marginleft=".125" 
    orientation="portrait" unit="in" encryption="none" fontembed="Yes" backgroundvisible="No" overwrite="Yes">

<style type="text/css">
   table, tr, td { font-size: 9px; font-family:Arial; }
</style>
<table width="100%" border="0" cellpadding="2" cellspacing="2" align="center" bordercolor="000000">
    <cfloop from="1" to="#Ceiling(qryCampers.recordcount/2)#" index="iRow">
    <tr valign="top">
        <cfloop from="#iRow - 1#" to="#iRow#" index="iCol">
        <cfif LEN(qryCampers.student_id[iRow + iCol]) GT 0>
        <cfquery name="qryMedInfo" datasource="#session.datasource#">
        SELECT * FROM tbl_medical_info_form WHERE mif_std_id = #qryCampers.student_id[iRow + iCol]# AND mif_trip_year = '#DateFormat(Now(), '01/01/yyyy')#'
        </cfquery>
        <td width="50%">
            <table width="100%" border="0" cellpadding="2" cellspacing="2" align="center">
                <tr valign="top">
                    <td height="25%">
                    <table width="100%" border="0" cellpadding="2" cellspacing="2" align="center">
                        <tr valign="top">
                            <td width="40%" align="center" valign="middle">
                                <cfif LEN(qryCampers.std_image_filename[iRow + iCol]) GT 0>
                                    <cfimage source="../photos/#qryCampers.std_image_filename[iRow + iCol]#" action="read" name="cardImage">
                                    <cfif cardImage.height GT cardImage.width>
                                        <img src="../photos/#qryCampers.std_image_filename[iRow + iCol]#" height="150">
                                    <cfelseif cardImage.height LTE cardImage.width>
                                        <img src="../photos/#qryCampers.std_image_filename[iRow + iCol]#" height="150">
                                    </cfif>
                                <cfelse>
                                    <img src="../images/no_image.gif" alt="" width="" height="150" border="0">
                                </cfif>
                            </td>
                            <td width="60%">
                                <cfif qryMedInfo.mif_c_alleriges EQ "Yes" OR LEN(qryMedInfo.mif_severe_allerigies) GT 0>
                                    <font color="FF0000" style="font-size:16px;">ALLERGIES</font><br>
                                </cfif>
                                <cfif qryMedInfo.mif_r_alcohol EQ "Yes">
                                    <font color="FF0000" style="font-size:16px;">ALLOWED TO DRINK</font><br>
                                <cfelse>
                                    <font color="FF0000" style="font-size:16px;">NOT ALLOWED TO DRINK</font><br>
                                </cfif>


                                <u>Parent Note</u> : <cfif qryMedInfo.mif_c_alleriges EQ "Yes">#qryMedInfo.mif_history_comments#</cfif><br>
                                <u><font color="FF0000">SEVERE ALLERGIES</font></u> : #qryMedInfo.mif_severe_allerigies#<br>
                                <br>
                                <u>Conditions</u> : #qryMedInfo.mif_med_conditions_1#<br>
                                <cfif Len(qryMedInfo.mif_med_conditions_2) GT 0>#qryMedInfo.mif_med_conditions_2#<br></cfif>                
                                <u>Medications</u> : <font color="FF0000">#TRIM(qryMedInfo.mif_med_taken_1)#</font><br>#TRIM(qryMedInfo.mif_med_taken_2)#<br>

                                <font color="FF0000"><u>CANNOT TAKE</u> : </font>
                                    <cfif qryMedInfo.mif_r_aspirin EQ "No">     Aspirin,</cfif>
                                    <cfif qryMedInfo.mif_r_pepto EQ "No">       Pepto Bismol,</cfif>
                                    <cfif qryMedInfo.mif_r_non_aspirin EQ "No"> Non-Apsirin (Acetaminophen/Tylenol),</cfif>
                                    <cfif qryMedInfo.mif_r_maalox EQ "No">      Maalox,</cfif>
                                    <cfif qryMedInfo.mif_r_nsaid EQ "No">       NSAID (Ibuprofen/Advil, Motrin or Naproxensodium/Aleve),</cfif>
                                    <cfif qryMedInfo.mif_r_immodium EQ "No">    Immodium,</cfif>
                                    <cfif qryMedInfo.mif_r_benadryl EQ "No">    Benadryl,</cfif>
                                    <cfif qryMedInfo.mif_r_simethicone EQ "No"> Simethicone (GasX),</cfif>
                                    <cfif qryMedInfo.mif_r_sudafed EQ "No">     Pseudoephedrine/Sudafed,</cfif>
                                    <cfif qryMedInfo.mif_r_tagamet EQ "No">     Tagamet or similar,</cfif>
                                    <cfif qryMedInfo.mif_r_cough EQ "No">       Cough Medicine,</cfif>
                                    <cfif qryMedInfo.mif_r_bandages EQ "No">    Bendages,</cfif>
                                    <cfif qryMedInfo.mif_r_throat EQ "No">      Throat Lozenges,</cfif>
                                    <cfif qryMedInfo.mif_r_antibiotic EQ "No">  Antibiotic Ointment,</cfif>
                                    <cfif qryMedInfo.mif_r_ex_anesthetic EQ "No">External Anesthetic (Calamine or the like),</cfif>
                                    <cfif qryMedInfo.mif_r_cortisone EQ "No">   Topical Cortisone Cream,</cfif>
                                    <cfif qryMedInfo.mif_r_tylenol_pm EQ "No">  Tylenol PM</cfif>
                                    <br>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <font style="font-size:16px;font-weight:bold;color:0000ff;">
                                    #qryCampers.std_first_name[iRow + iCol]# #qryCampers.std_last_name[iRow + iCol]#
                                </font><br>
                                <br>
                                <u>Emergency Contact</u> : #qryMedInfo.mif_emerg_name#&nbsp;&nbsp;&nbsp;<cf_phoneoutput startstring="#GetNumbers(qryMedInfo.mif_emerg_phone)#"><br>
                                <br>
                                <u>Father/Gaurdian</u> : #qryCampers.ftr_first_name[iRow + iCol]# #qryCampers.ftr_last_name[iRow + iCol]#&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;<u>(H)</u> <cf_phoneoutput startstring="#GetNumbers(qryCampers.ftr_main_phone[iRow + iCol])#">&nbsp;&nbsp;&nbsp;or&nbsp;&nbsp;&nbsp;<u>(C)</u> <cf_phoneoutput startstring="#GetNumbers(qryCampers.ftr_cell_phone[iRow + iCol])#"><br>
                                <u>Mother/Gaurdian</u> : #qryCampers.mtr_first_name[iRow + iCol]# #qryCampers.mtr_last_name[iRow + iCol]#&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;<u>(H)</u> <cf_phoneoutput startstring="#GetNumbers(qryCampers.mtr_main_phone[iRow + iCol])#">&nbsp;&nbsp;&nbsp;or&nbsp;&nbsp;&nbsp;<u>(C)</u> <cf_phoneoutput startstring="#GetNumbers(qryCampers.mtr_cell_phone[iRow + iCol])#"><br>
                            </td>
                        </tr>
                    </table>
                    </td>
                </tr>
            </table>
        </td>
        <cfelse>
            <td width="50%">&nbsp;</td>
        </cfif>
        </cfloop>       
    </tr>
    <cfif iRow MOD 4 IS 0>
    <tr>
        <td>&nbsp;</td>
    </tr>
    </cfif>
    </cfloop>
</table>
</cfdocument>
Macness
  • 1,226
  • 2
  • 13
  • 24
  • 1
    if you just display the code without the cfdocument tag around it, is it still slow? – steve Feb 07 '13 at 16:30
  • Just tried this. It's not slow! Also I think it does bomb out on a particular image... I get some of the images, then the error. – Macness Feb 07 '13 at 16:39
  • I think the error is telling you the problem - `Invalid image format`. One (or more) of your images may be invalid as a jpg. I would add some debug code in your loop to display the image file names as it goes. When it crashes you will know what file it was on. Examine that image file for correctness. Fix it or replace it with a known good one and step through again. – Miguel-F Feb 07 '13 at 16:53
  • I would also try considering wrapping your cfimage with a tag. It may be possible that although the DB had the filename, it doesnt exist on your server for some reason or another. – steve Feb 07 '13 at 17:13

3 Answers3

1

It sounds like the image found in this line <cfimage source="../photos/#qryCampers.std_image_filename[iRow + iCol]#" action="read" name="cardImage"> is not a valid image format. Are you sure what it is trying to read there is an image?

Leeish
  • 5,203
  • 2
  • 17
  • 45
  • Yes, it does work in some cases, the query I pull up in SQL gives these results: `std_image_filename NULL NULL Ellen_Lapkiewicz_01-21-2013.jpg Allison_Mackel_06-01-2012.jpg Elizabeth_Harkins_06-01-2012.jpg Teresita_Liebel_06-01-2012.jpg Alexandria_Garvey_10-20-2012.jpg NULL Madeline_Beck_01-15-2013.jpg Julia_Haney_01-16-2013.jpg NULL NULL` and they are all valid images in the that folder. – Macness Feb 07 '13 at 16:35
1

Have you tried using "isImage"?

 <cfif trim(qryCampers.std_image_filename[iRow + iCol]) neq '' 
          AND isImage('../photos/#qryCampers.std_image_filename[iRow + iCol]#')>

I agree with @Leeish that the CFImage tag is getting something that it doesn't recognize as an image. I have had time when I've had a jpg that was marked as a jpg and I could view it in a browser but then I tried to pull it up in photoshop or something similar I found that there was a aheader problem in the jpg itself that was preventing cfimage or cfx_ImageCR (which I prefer).

Lance
  • 3,193
  • 2
  • 32
  • 49
1

As far as your invalid image error, we had a similar issue with invalid formats and slow performance. Our solution was to convert the image to a png then back to jpg using cfimage. We did it as the image was uploaded but you could do the same thing in your situation.

<cfimage source="#expandPath('\images\temp')#\#cffile.serverFile#" action="convert" destination="#expandPath('\images\temp')#\#cffile.serverFileName#.png" overwrite="yes">
<cfimage source="#expandPath('\images\temp')#\#cffile.serverFileName#.png" action="convert" destination="#expandPath('\images\temp')#\#cffile.serverFileName#.jpg" overwrite="yes">
genericHCU
  • 4,394
  • 2
  • 22
  • 34
  • Yup, We have done this approach too. It solves part of the problem I was talking about in my answer about the headers in the image file being fubar by re-writing them – Lance Feb 07 '13 at 17:39
  • You guys were on the right track but neither of your "answers" provided a solution other than to say "yep, it's a bad image, here's how you can tell." – genericHCU Feb 07 '13 at 17:45
  • Some quick testing allowed me to find the problem child where isImage failed me! I took a screenshot of the image and replaced it and it worked. This is going to be a good long term solution. – Macness Feb 07 '13 at 18:33