1

试图解决别人的不太好的代码。任何想法将不胜感激。它似乎在<cfif>带来图像时爆炸:

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

如果我注释掉 if(并且只将与“no_image.gif”相关的部分保留在cfif语句之外)我们很好。文档出现。

CF Server 8,SQL Server 2000,图像尺寸相对较小(全部小于 30kb,宽度不超过 300px),此代码有时会起作用,当它起作用时,加载 PDF 需要永远。此特定查询(仅 12 条记录)导致错误。

错误:

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

cfdocument代码:

<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>
4

3 回答 3

1

听起来在这一行<cfimage source="../photos/#qryCampers.std_image_filename[iRow + iCol]#" action="read" name="cardImage">中找到的图像不是有效的图像格式。你确定它试图读取的是图像吗?

于 2013-02-07T16:32:12.677 回答
1

您是否尝试过使用“isImage”?

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

我同意@Leeish 的观点,即 CFImage 标签正在获取它无法识别为图像的东西。我曾经有过一段时间,我有一个标记为 jpg 的 jpg,我可以在浏览器中查看它,但后来我尝试在 photoshop 或类似的东西中将其拉起,我发现 jpg 本身存在一个前导问题这阻止了 cfimage 或 cfx_ImageCR (我更喜欢)。

于 2013-02-07T16:48:35.130 回答
1

至于您的无效图像错误,我们遇到了类似的格式无效和性能缓慢的问题。我们的解决方案是将图像转换为 png,然后使用 cfimage 转换回 jpg。我们在上传图片时这样做了,但您可以在您的情况下做同样的事情。

<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">
于 2013-02-07T17:07:55.960 回答