Copy link to clipboard
Copied
When trying to resize a jpg using cfimage I receive the following error "attempt to read data outside of exif segment". Any ideas on what causes this or how to fix it? This only happens on certain images. Sample image it happens with attached, this photo is subject to copyright restrictions and should be treated appropriately. Thanks for any help.
Resize Code attached.
<!--- Set some defaults used by each image type, unless you override them --->
<cfparam name="jpgQuality" default=".8" />
<cfparam name="defaultInterpolation" default="bicubic" />
<cfparam name="defaultBackground" default="black" />
<!--- Set values for each image type --->
<cfparam name="thumbMaxWidth" default="" /> <!--- leave blank to allow any width (forced to size by height) --->
<cfparam name="thumbMaxHeight" default="60" /> <!--- leave blank to allow any height (forced to size by width, above) --->
<cfparam name="thumbQuality" default="1" /> <!--- number from 0 - 1, 1 being the best --->
<cfparam name="thumbFixedSize" default="false" /> <!--- you MUST set both MaxWidth & MaxHeight to use FixedSize --->
<cfparam name="thumbBackground" default="#defaultBackground#" /> <!--- color of background if fixed size is used --->
<cfparam name="thumbInterpolation" default="#defaultInterpolation#" /> <!--- Interpolation method used for resizing (HUGE performance hit depending on what is used) --->
<cfparam name="normalMaxWidth" default="476" />
<cfparam name="normalMaxHeight" default="324" />
<cfparam name="normalQuality" default="#jpgQuality#" />
<cfparam name="normalFixedSize" default="true" />
<cfparam name="normalBackground" default="#defaultBackground#" />
<cfparam name="normalInterpolation" default="#defaultInterpolation#" />
<cfparam name="zoomMaxWidth" default="670" />
<cfparam name="zoomMaxHeight" default="380" />
<cfparam name="zoomQuality" default="#jpgQuality#" />
<cfparam name="zoomFixedSize" default="true" />
<cfparam name="zoomBackground" default="#defaultBackground#" />
<cfparam name="zoomInterpolation" default="#defaultInterpolation#" />
<!--- Set values for folder paths and the watermark image --->
<cfparam name="originalFolder" default="path to folder for original images" />
<cfparam name="thumbFolder" default="path to folder for thumbnail images" />
<cfparam name="normalFolder" default="path to folder for large images" />
<cfparam name="zoomFolder" default="path to folder for large resized images" />
<cfparam name="watermarkImage" default="" />
<cfparam name="wmXPosition" default="50" /> <!--- value is a number from 0 - 100, 50 = centered --->
<cfparam name="wmYPosition" default="65" />
<cffunction name="genWatermarkImage">
<cfargument name="ImageFile" required="true" />
<cfargument name="MaxWidth" required="true" />
<cfargument name="MaxHeight" required="true" />
<cfargument name="StorePath" required="true" />
<cfargument name="FixedSize" required="true" type="Boolean" />
<cfargument name="Background" required="true" />
<cfargument name="Quality" required="true" />
<cfargument name="Interpolation" required="true" />
<cfargument name="AddWatermark" required="true" type="Boolean" />
<cfif IsImageFile(originalFolder & ImageFile)>
<cfset original = ImageNew(originalFolder & ImageFile) />
<cfset originalHeight = ImageGetHeight(original) />
<cfset originalWidth = ImageGetWidth(original) />
<cfset outfile = StorePath & ImageFile />
<cfset watermark = ImageNew(watermarkImage) />
<cfset ImageScaleToFit(original,MaxWidth,MaxHeight,Interpolation) />
<cfset new_w = ImageGetWidth(original) />
<cfset new_h = ImageGetHeight(original) />
<cfif FixedSize>
<cfset normal = ImageNew("",MaxWidth,MaxHeight,"rgb",Background) />
<cfset ImagePaste(normal,original,int((MaxWidth-new_w)/2),int((MaxHeight-new_h)/2)) />
<cfif AddWatermark>
<cfset ImagePaste(normal,watermark,( int(ImageGetWidth(normal)) - int(ImageGetWidth(watermark)) -3),( int(ImageGetHeight(normal)) - int(ImageGetHeight(watermark)) -3) )/>
</cfif>
<cfset ImageWrite(normal,outfile,Quality) />
<cfelse>
<cfif AddWatermark>
<cfset ImagePaste(original,watermark,( int(ImageGetWidth(normal)) - int(ImageGetWidth(watermark)) -3), (int(ImageGetHeight(normal)) - int(ImageGetHeight(watermark)) -3) )/>
</cfif>
<cfset ImageWrite(original,outfile,Quality) />
</cfif>
<cfelse>
<cfreturn "Image file not an image!" />
</cfif>
</cffunction>
<cfset zoomError = genWatermarkImage(Filename,zoomMaxWidth,zoomMaxHeight,zoomFolder,zoomFixedSize,zoomBackground,zoomQuality,zoomInterpolation,dowatermark) />
Copy link to clipboard
Copied
You might see if this blog entry is of any help
http://www.coldfusionjedi.com/index.cfm/2009/7/15/Error-resizing-a-JPG-with-ColdFusion
Copy link to clipboard
Copied
Yes I should have posted that I had already tried that fix and it didn't work.
Copy link to clipboard
Copied
Hmm, that was my best shot.
1) Do you have all of the latest updates applied?
2) Did you try all of the work-arounds listed in the comments. Granted some of them are definite hacks
3) Just to cover all the bases, do you get the same result with both ImageResize() and ImageScaleToFit()?
If all else fails, you could always go the java route and try some java code to do the resize. Obviously not the ideal, but it is worth a shot. IIRC there is a thread around here somewhere with the cf/java code. But that was from before the switch in forums and I will be darned if I can find it right now!
Update: I will play around the sample image you posted tomorrow. Just to see if I can come up with anything.
Copy link to clipboard
Copied
I downloaded the image and was not able to reproduce that error.
Could you upload the image in a .zip file and a few lines of code that reproduce the error, rather than the whole function?