insert into DB and output blob images using Coldfusion 10
I have been working on a script that will allow users to asynchronously
upload images.
the script contains several segments of code and while most of it works
like a charm i've been experiencing issue while trying to convert
coldfusion image object to blob, pass it to another object (cfc component
method), insert values to DB using stored procedure and finaly output blob
images to see the result.
here is the testing code for particular segment i am having issues with,
the final one will be a bit more complex:
<cfimage source="#CFFILE.ServerDirectory#\#CFFILE.ServerFile#"
name="Image" overwrite="no">
<cfif ImageGetWidth(Image) lt 1024>
<cfset ArrayAppend(set.Errors,"you can not add image that's less
than 1024px wide")>
<cfelse>
<!---now resize image scale to fit (709px wide)--->
<cfset ImageSetAntialiasing(Image,"on")>
<cfset ImageScaleToFit(Image,709,"","highestPerformance")>
<!---now crop image if height is more than 350px--->
<cfif ImageGetHeight(Image) gt 350>
<cfif ImageGetHeight(Image) gt 350>
<cfset yPosition = (ImageGetHeight(Image) - 350) / 2>
<cfset ImageCrop(Image, 0, #yPosition#,
#ImageGetWidth(Image)#, 350)>
</cfif>
</cfif>
</cfif>
<cfif ArrayLen (set.Errors) is 0>
<cfset testAddImage = testImg.AddImage(finalImage=#ImageGetBlob(Image)#)>
</cfif>
need to admit that did not use much image functions with CF, hence I have
to learn a few tricks. anyway, as i can see this testing code apparently
works considering that all values are neatly added to the DB every time
the form has been submited and no CF nor client side errors are thrown. on
the other hand, although I read a lot about outputting blob I am pretty
much confused what's the best approach to achieve this with CF 10. that
said, should I use cfcontent, binaryEncode, to string or something else to
do it right.
I've also tried to set a binary object, cffile action = "readBinary"... as
well as set ImageNew , however as I could see everything was the same. is
there a difference between a binary and image object!?
No comments:
Post a Comment