I need to rotate an image in Coldfusion and then once rotated it updated the file with the new rotation. So far this is what I have:
<cfimage source="../imgupload/image1.jpg" name="myImage">
<cfset ImageRotate(myImage,90,"bicubic")>
<cfimage source="#myImage#" destination="image1.jpg" action="write" overwrite="yes">
<img src="../imgupload/image1.jpg" width="600">
However, when the file is displayed on the 4th line, it shows the original "non-rotated" image. Any help would be appreciated.
Regards Sam
Change the file path on line 3 or on line 4.
Since you are watching an image from the source folder
<cfimage source="../imgupload/image1.jpg" name="myImage">
<cfset ImageRotate(myImage,90,"bicubic")>
<cfimage source="#myImage#" destination="../imgupload/image1.jpg" action="write" overwrite="yes">
<img src="../imgupload/image1.jpg" width="600">
OR
<cfimage source="../imgupload/image1.jpg" name="myImage">
<cfset ImageRotate(myImage,90,"bicubic")>
<cfimage source="#myImage#" destination="image1.jpg" action="write" overwrite="yes">
<img src="image1.jpg" width="600">
Related
I have function that will generate cfdocument pdf file. Then I would like to return the document and server to the browser. Here is example of the function that generates the pdf file.
<cftry>
<cfdocument format="PDF" filename="file.pdf" overwrite="Yes">
<table>
<tr>
<td>Test</td>
</tr>
</table>
</cfdocument>
<cfset local.fnResults = {file: //Here I'm not sure what I should return}>
<cfcatch type="any">
<cfset local.fnResults = {status : 400, message : "Error! Something went wrong."}>
</cfcatch>
</cftry>
<cfreturn fnResults>
Function above should genrate the file and return PDF in fnResults structure. Then on serve.cfm I have this logic:
<cfset local.Results = genertePDF()>
<cfif structKeyExists(local.Results, "FILEPATH")>
<cfheader name="content-disposition" value="attachment;filename=#local.Results["FILENAME"]#"/>
<!---Add the file content to the output stream:--->
<cfcontent file="#local.Results["FILEPATH"]#" type="application/octet-stream" reset="true"/>
<!---Exit immediately after adding the file content to avoid corrupting it:--->
<cfabort/>
<cfif>
You can ignore the structure of RESULTS since I haven't modified everything. My only problem here is to figure out how to return cfdocument content? If anyone knows how to get this to work please let me know. Thank you.
Change:
<cfheader name="content-disposition" value="attachment;filename=#local.Results["FILENAME"]#"/>
To:
<cfheader name="content-disposition" value="inline;filename=#local.Results["FILENAME"]#"/>
Reference
I am creating a PDF document using ColdFusion cfdocument tag. Works fine, however instead of showing the document name in browser Title - it shows the .cfc file that I call to create the PDF.
Here is how I'm calling it.
<cfdocument format="pdf" marginbottom=".5" margintop=".25" marginright=".5" marginleft=".5" saveAsName="#filename#.pdf">
<cfdocumentitem type="footer">
<p style="font-size:11px; text-align:right; font-style:italic;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p>
</cfdocumentitem>
<html>
<head><title>#filename#.pdf</title></head>
<body><img src="file:///#application.tempFolder#\#thisFilename#" /></body>
</html>
</cfdocument>
What the heck am I missing? Why does it still show the filename.cfc file that I'm calling in the browser title instead of the filename I give to the PDF???
Figured it out. Had to create the document using CFDOCUMENT, then add a "Title" attribute to it using the CFPDF tag. Then output it to the browser.
<!--- Create the PDF --->
<cfdocument format="pdf" marginbottom=".5" margintop=".25" marginright=".5" marginleft=".5" filename="#application.tempFolder#\#thisSaveAsFilename#" overwrite="yes">
<cfdocumentitem type="footer">
<p style="font-size:11px; text-align:right; font-style:italic;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p>
</cfdocumentitem>
<html>
<head><title>#thisSaveAsFilename#</title></head>
<body><img src="file:///#application.tempFolder#\#thisFilename#" /></body>
</html>
</cfdocument>
<!--- Use CFPDF to add attributes to it --->
<cfset thisInfo = StructNew()>
<cfset thisInfo.Title = "pdf title goes here...">
<cfpdf action="setinfo" info="#thisInfo#" source="#application.tempFolder#\#thisSaveAsFilename#" />
<!--- Send it to the browser --->
<cfcontent file="#application.tempFolder#\#thisSaveAsFilename#" type="application/pdf" />A
I have a URL that goes to a pdf file. In my coldfusion page, I want to allow the user to download the file (using the open/save dialog or however that particular browser handles it).
This is the code I have so far:
<cfset tempFile = getTempFile(getTempDirectory(), 'testfile') />
<cfhttp url="myUrl/myFile.pdf" method="get" file="#tempFile#"/>
<cfheader name="Content-Disposition" value="attachment; filename=myFile.pdf">
<cfcontent type="application/pdf" file="#tempFile#">
This seems to work... but when I try to open the file it tells me something's wrong with the file. What am I doing wrong?
file attribute: Do not specify the path to the directory in this attribute; use
the path attribute.
Try separating the file name and path:
<!--- hard coded for clarity --->
<cfhttp url="http://www.somesite.com/path/testFile.pdf"
method="get"
getAsBinary="yes"
path="c:/test/"
file="testFile.pdf"/>
<cfheader name="Content-Disposition" value="attachment; filename=myFile.pdf" />
<cfcontent type="application/pdf" file="c:/test/testFile.pdf" />
For smaller files you might skip the temp file and use <cfcontent variable..>
<cfhttp url="http://download.macromedia.com/pub/documentation/en/coldfusion/mx7/cfmx7_cfml_qref.pdf"
method="get"
getAsBinary="yes" />
<cfheader name="Content-Disposition" value="attachment; filename=myFile.pdf" />
<cfcontent type="application/pdf" variable="#cfhttp.fileContent#" />
Update: Dynamic example using a temp file
<cfset tempDir = getTempDirectory() />
<cfset tempFile = getFileFromPath(getTempFile(tempDir, "testfile")) />
<!--- uncomment to verify paths
<cfoutput>
tempDir = #tempDir#<br />
tempFile = #tempFile#<br />
</cfoutput>
<cfabort />
--->
<cfhttp url="http://download.macromedia.com/pub/documentation/en/coldfusion/mx7/cfmx7_cfml_qref.pdf"
method="get"
getAsBinary="yes"
path="#tempDir#"
file="#tempFile#" />
<cfheader name="Content-Disposition" value="attachment; filename=myFile.pdf" />
<cfcontent type="application/pdf" file="#tempDir#/#tempFile#" />
As far as I know, your coding is fine in Google Chrome. In IE, error message prompt. It's because of "file path" cannot support for URL path. Should use directory path instead of URL path.
I am trying to compare images and find if they are same or not. Images can have same name but the actual image might be different. The code that I have so far.
<cfset dirToReadFrom = #ExpandPath( '../properties-feed/unzipped/' )# />
<cfdirectory
action="list"
directory="#dirToReadFrom#"
listinfo="name"
name="qFile"
sort="asc"
filter="*.jpg"
/>
<cfset images = ArrayNew(1)>
<cfoutput query="qFile">
<cfset ArrayAppend(images, #qFile.name#)>
</cfoutput>
<cfset dirToCreate = #ExpandPath( './assets/images/resized/original/' )# />
<cfif not DirectoryExists(dirToCreate)>
<cfdirectory action = "create" directory = "#dirToCreate#" />
<cfoutput><p>Your directory has been created.</p></cfoutput>
</cfif>
<cfzip
action="unzip"
file="#ExpandPath( '../properties-feed/data.zip/' )#"
destination="#ExpandPath( './assets/images/resized/original/' )#"
overwrite="true"
/>
<cfset dirToReadFromOriginal = #ExpandPath( './assets/images/resized/original/' )# />
<cfdirectory
action="list"
directory="#dirToReadFromOriginal#"
listinfo="name"
name="qFileOriginal"
sort="asc"
filter="*.jpg"
/>
<cfset imagesLatest = ArrayNew(1)>
<cfoutput query="qFileOriginal">
<cfset ArrayAppend(imagesLatest, #qFileOriginal.name#)>
</cfoutput>
<!--- Loop over your current images --->
<cfloop query="qFileOriginal">
<!--- Check for a matching file name --->
<cfquery name="fileExists" dbtype="query">
SELECT
COUNT(*) AS num_Rec
FROM
qfile
WHERE
name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#qFileOriginal.name#" />
</cfquery>
<!--- do we have a matching file name? --->
<cfif val(fileExists.num_rec)>
<cfimage action="read" name="newImage" source="#dirToReadFrom##qFile.name#"/>
<cfimage action="read" name="originalImage" source="#dirToReadFromOriginal##qFileOriginal.name#"/>
<cfset newImageBlob = ImageGetBlob(newImage) />
<cfset originalImageBlob = ImageGetBlob(originalImage) />
<!--- Compare --->
<cfif toString(newImageBlob) eq toString(originalImageBlob) >
Images are same
<cfelse>
DIFFERENT
</cfif>
</cfif>
</cfloop>
The code doesn't seem to be working. Can Anyone see what am I doing wrong?
Update 1 from comments
The result that I actually get is that the first images are same and the rest of images in files are different. But this is not correct as most of the images that I am comparing are same.
Update 2 from comments
It incorrectly identifies same images as being different. What I actually get is that the first two images are same and the rest is different. Which is not right as most of the images I have are same.
I've always just done this with BinaryEncode(), and then compare the resulting strings. You have to be careful though, as compression can make the files different even though they look (to the eye) exactly the same.
<cfquery name="writefile" datasource="#dsn#">
SELECT abc,def,pqr,stu,zex
FROM mytable
</cfquery>
<cfoutput>
<table>
<cfloop query="writefile">
<tr>
<cfloop list="#ArrayToList(writefile.getColumnNames())#" index="col">
<cffile action="write" file="d:\test.txt" output="#writefile[col][currentrow]#">
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
I am using the above code to write a text file to a location using cffile.
But the text file is not containing all the results of the query. Please guide me.
Using cffile action="write" will reset the file each time.
Use action="append" to add content to a file without first blanking the file.
You should also consider building the string first, then writing to the file in a single action.
For example:
<cfset Content = "" />
<cfloop query="writefile">
<cfloop array=#writefile.getColumnNames()# index="col">
<cfset Content &= ' ' & writefile[col][currentrow] />
</cfloop>
<cfset Content &= chr(10) />
</cfloop>
<cffile action="write" file="d:\test.txt" output="#FileContent#" />
(Note: string concatenation used for simplicity - if performance matters, consider using StringBuilder and/or cfsavecontent instead.)