I'm running Coldfuison8
and have trouble with an image file upload, where I seem to often end up with users trying to upload CMYK JPEG files.
While the upload works fine (I don't get any errors) and isImageFile
also returns yes
, the colors of the loaded image are distorted.
Only doing this already saves the wrong colored image to the server:
<cffile result="temp"
action="upload"
accept="image/jpeg,image/jpg"
filefield="Dateiname8"
destination="#variables.tempDirectory#"
nameconflict="overwrite" />
Question:
If isImageFile
does not produce an error, Coldfusion correctly identifies the image. What do I need to do to display it correctly?
EDIT1:
By distorted I mean, the file looks like this:
and ends up like this:
EDIT2:
<cfhttp timeout="45"
throwonerror="no"
url="#LOCAL.testFilePath#"
method="get"
useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"
getasbinary="yes"
result="LOCAL.objGet">
<cfset LOCAL.objImage = ImageNew(LOCAL.objGet.FileContent)>
<cfset LOCAL.ext = ".png">
<cfset LOCAL.basePath = LOCAL.tempDirectory & "_base_" & LOCAL.file & LOCAL.ext>
<cfset imageWrite( LOCAL.objImage, LOCAL.basePath, ".99")>
So, I'm splitting the filename into file
and ext
and then replace the extension with .png
. The file gets created, but has 0 file size with the error thrown.
Any idea what might be causing this?
EDIT3:
Here is my script using imageMagick
:
<cffile result="temp" action="upload" accept="image/jpeg,image/jpg" filefield="Dateiname8" destination="#variables.tempDirectory#" nameconflict="overwrite" />
<cfset variables.testFilePath = variables.tempDirectory & temp.serverFile>
<!--- imageMagick for CMYK uploads --->
<cftry>
<cfimage action="info" source="#variables.testFilePath#" structname="cmyk" />
<cfcatch type="any">
<cftry>
<cfexecute name="#expandpath("../tools/imageMagick/convert.exe")#" arguments="#variables.testFilePath# -strip -colorspace rgb -quality 100 #variables.testFilePath#" timeout="30" variable="msg" />
<cfcatch>
<cfdump output="dump.txt" label="catch" var="type: #cfcatch.type#">
<cfdump output="dump.txt" label="catch" var="message: #cfcatch.message#">
<cfdump output="dump.txt" label="catch" var="detail: #cfcatch.detail#">
</cfcatch>
</cftry>
</cfcatch>
</cftry>
<!--- Image can now be read --->
<cfimage action="info" source="#variables.testFilePath#" structname="cmyk" />
ImageMagick ran fine, but the image was still tainted. I then tried this:
<cfset variables.testFilePath = variables.tempDirectory & temp.serverFile>
<cfset variables.try = ImageRead( variables.testFilePath )>
<cfset ImageNegative( variables.try )>
<cfset ImageWrite( variables.try, variables.testFilePath, "0.99")>
And it created the correct image. Only problem is how to check for CMYK on the original image. Then I wouldn't need to use ImageMagick.
EDIT4:
And this is the full error I'm getting when trying to save the image as a png
Detail: Ensure that the file is a vaild image file.
Message: ColdFusion was unable to create an image from the specified source file.
StackTrace: coldfusion.image.ImageReader$UnableToCreateImageException: ColdFusion was unable to create an image from the specified source file.
at coldfusion.image.ImageReader.readImage(ImageReader.java:114)
at coldfusion.image.Image.<init>(Image.java:236)
at coldfusion.runtime.CFPage.ImageRead(CFPage.java:5841)
at cfform_img_handler2ecfc1184626149$funcUPLOAD.runFunction(E:123)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418)
at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:324)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:463)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:453)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:320)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2222)
at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:358)
at cfhs_herstellerprofil2ecfm1153584487._factor19(E:559)
at cfhs_herstellerprofil2ecfm1153584487._factor21(E:514)
at cfhs_herstellerprofil2ecfm1153584487._factor22(E:511)
at cfhs_herstellerprofil2ecfm1153584487._factor41(E:502)
at cfhs_herstellerprofil2ecfm1153584487.runPage(E:1)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:483)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:282)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126)
at coldfusion.CfmServlet.service(CfmServlet.java:198)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
TagContext: ...
Type: Application
[object of coldfusion.image.ImageReader$UnableToCreateImageException] Class Name: coldfusion.image.ImageReader$UnableToCreateImageException
Parent Class: [object of coldfusion.image.ImageException] Class Name: coldfusion.image.ImageException
Parent Class: [object of coldfusion.runtime.ApplicationException]
Class Name: coldfusion.runtime.ApplicationException
Parent Class: [object of coldfusion.runtime.NeoException]
Class Name: coldfusion.runtime.NeoException
Methods:
findAdvancedCFTarget(coldfusion.runtime.AdvancedCFException, java.lang.String[]) returns int
findCustomTarget(coldfusion.runtime.CustomException, java.lang.String[]) returns int
findThrowableTarget(java.lang.Throwable, java.lang.String[]) returns int
getDetail() returns java.lang.String
getLocalizedMessage() returns java.lang.String
getMessage() returns java.lang.String
getRootCause() returns java.lang.Throwable
getString(java.lang.Throwable, java.lang.String, java.util.Locale) returns java.lang.String
getType() returns java.lang.String
setLocale(java.util.Locale) returns void
unwrap(java.lang.Throwable) returns java.lang.Throwable
Parent Class: [object of java.lang.RuntimeException]
Class Name: java.lang.RuntimeException
Parent Class: [object of java.lang.Exception]
Class Name: java.lang.Exception
Parent Class: [object of java.lang.Throwable]
Class Name: java.lang.Throwable
Methods:
fillInStackTrace() returns java.lang.Throwable
getCause() returns java.lang.Throwable
getLocalizedMessage() returns java.lang.String
getMessage() returns java.lang.String
getStackTrace() returns java.lang.StackTraceElement[]
initCause(java.lang.Throwable) returns java.lang.Throwable
printStackTrace(java.io.PrintWriter) returns void
printStackTrace(java.io.PrintStream) returns void
printStackTrace() returns void
setStackTrace(java.lang.StackTraceElement[]) returns void
toString() returns java.lang.String