image-processingcoldfusioncoldfusion-8cfimage

Coldfusion 8 Error: Invalid image format or slow performance


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>

Solution

  • 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">