** Coldfusion Thread - Codes , Help, APIs,

Whats your Language of Choice?


  • Total voters
    14
Status
Not open for further replies.
Creating Thumbnails, and Re-sizing pictures after uploading can be a pain in the ass. This code will re-size your images, keeping aspect ratio. This can be made into a function, however, I just have it as a .cfm. You would include this, after your upload of the picture ..This will resize your image, to a maximum height of 600, and max width of 450.


perform_process_image.cfm

Code:
<cfoutput>
#currentpath#\img\uploadimages\#imagename#
<CFSET currentpath = ExpandPath("./")> 
<cfimage action="info" structname="imagetemp" source="#currentpath#img\uploadimages\#imagename#">
<cfset x=min(600/imagetemp.width, 450/imagetemp.height)>
<cfset newwidth = x*imagetemp.width>
<cfset newheight = x*imagetemp.height>
<cfif newheight LT 20>
<cfset newheight = 40>
</cfif>
<cfif newwidth LT 20>
<cfset newwidth = 40>
</cfif>
<cfimage action="resize" source="#currentpath#img\uploadimages\#imagename#" overwrite = "true" width="#newwidth#" height="#newheight#" destination="#currentpath#gallery\images\#imagename#">
</cfoutput>

This is extremely usefull for clients that do not use phoshop, and need to upload images to your application, wheather it be a real estate engine, or anything with a picture. I would create 2 of these actions, and include them after your upload. One for regular picture size, which we see here, and one for your thumbnail image..Here is my thumbnail image re-size code. It does not re-size, but rather, starts at the top, and goes 60 accross, and 60 down, then crops it. This makes for a much better looking thumbnail image, then a re-sized one that may be off ratio ....This one is a little more complicated ...

Perform_process_thumbnail_image.cfm

Code:
<cfoutput>
 
<CFSET currentpath = ExpandPath("./")> 
<cfimage action="info" structname="imagetemp" source="#currentpath#img\uploadimages\#imagename#">
<br /><br />oldwidth|#imagetemp.width# - 
oldheight|#imagetemp.height#
 
<cfif imagetemp.width GT imagetemp.height>
- HORIZONTAL<br />
<cfset x=min(190/imagetemp.width, 135/imagetemp.height)>
<cfelse>
 
-VERTICAL<br />
<cfset x=min(190/imagetemp.width, 135/imagetemp.height)>
 
 

</cfif>
<cfset newwidth = x*imagetemp.width>
<cfset newheight = x*imagetemp.height>
<br />newwidth|#newwidth# <br /> 
newheight|#newheight# <br />
<cfset newheight = #round(newheight)#>
<cfif newheight LT 20>
<cfset newheight = 40>
</cfif>
<cfif newwidth LT 20>
<cfset newwidth = 40>
</cfif>
 
 <cfimage action="resize" source="#currentpath#img\uploadimages\#imagename#" overwrite = "true" width="#newwidth#" height="#newheight#" destination="#currentpath#gallery\images\fromthegallery\#imagename#">
 
<cfimage action="read" name="img1" source="#currentpath#gallery\images\fromthegallery\#imagename#">
<cfoutput>
#imagetemp.width#<br />
#img1#</cfoutput>
<cfset ImageCrop(img1,10,10,imagetemp.width,135)>
 <cfif imagetemp.height GT imagetemp.width>  
 
<cfimage source="#img1#" action="write" destination="#currentpath#gallery\images\fromthegallery\#imagename#" overwrite="yes">
<img src="\gallery\images\fromthegallery\#imagename#" />
 
</cfif>
 

 
<cfimage action="read" namer="img2" source="#currentpath#gallery\images\fromthegallery\#imagename#">

<cfset ImageCrop(img2,0,0,100,100)>
<cfimage source="#img2#" action="write" destination="#currentpath#gallery\images\thumbnails\#imagename#" overwrite="yes">
<img src="\gallery\images\thumbnails\#imagename#" />
</cfoutput>

Just do a <cfinclude template="perform_proccess_image.cfm">
after your upload call, and your original image will be saved, and your resized images will apear in the appropriate folder. You can also do a delete on the original picture that is uploaded if you like, I keep it there, unless hosting has limited space.:Yahoo_29:
 


PHP is better supported by webhosts, more used across the internet and based on C/Perl so you can pick it up quick. Not to mention all the example code.

kick ass community + 1,000,000 hosting options = PHP pwns CF

Functions/oop can be written easily in most languages so the image resizing and mail functions that are being posted here really aren't anything novel. However, I encourage you to continue so that I can point any CF coders your way then they need help ... all 3 of them.

perl has it's place on the net too. I've never had a problem that php+perl couldn't fix so I really don't have a need to go to any other language ... though I admit I'm intrigued by python.
 
kick ass community + 1,000,000 hosting options = PHP pwns CF

Functions/oop can be written easily in most languages so the image resizing and mail functions that are being posted here really aren't anything novel. However, I encourage you to continue so that I can point any CF coders your way then they need help ... all 3 of them.

perl has it's place on the net too. I've never had a problem that php+perl couldn't fix so I really don't have a need to go to any other language ... though I admit I'm intrigued by python.


thanks for the useless post
 
okay, well add 1 million records into a msql table with CF , and also a mysql datasource with PHP, then run performance reports on both. I will guarentee you CF will be faster, and THATS not an opinion.

How can you say it's CF that is faster when you have two variables changing in the comparison? A valid comparison would be PHP/MySQL vs. CF/MySQL or PHP/MSSQL vs. CF/MSSQL.
 
holy shit you guys are dicks. give the guy a break, i've never used coldfusion in my life and prefer php.. but damn this is a more useful thread to at least a few people than most of the shit that gets posted here these days.
 
Scraping Pages with Cold Fusion

How to Scrape Pages with Coldfusion ...Create over 20,000 records in 5 minutes:

Code:
<cfloop from="500" to="5000" index="LoopCount">
<cfhttp url="http://www.articles-hub.com/Article/#loopcount#.html" method="GET">
<cfset sDoc = trim(cfhttp.fileContent)>
<cfset regExp = '<span class="article_display_title" > 

        ([\s\S]*?)</span>[\s\S]*?<div align=[\s\S]*?
</div>
    ([\s\S]*?)
          </div>
            </div>'>
<cfset q_srch = queryNew("title, article")>
<cfset start = 1>
<cfloop condition="#start#">
  <cfset stResult = REfindNoCase(regExp,sDoc,start,"Yes")>
  <cfif stResult.pos[1]>
     <cfset queryAddRow(q_srch)>
     <cfset querySetCell(q_srch,"article",mid(sDoc,stResult.pos[3],stResult.len[3]))>
     <cfset querySetCell(q_srch,"title",mid(sDoc,stResult.pos[2],stResult.len[2]))>
  </cfif>
  <cfset start = stResult.pos[1] + stResult.len[1]>
</cfloop>
<cfquery name="insert_data" datasource="localdev">
INSERT article_dump(title,content) VALUES('#q_srch.title#','#q_srch.article#')
</cfquery>
</cfloop>

Original Post:
Scraping with ColdFusion: How to Scrape Pages With ColdFusion
 
Scraping Google SERPs with ColdFusion

Scraping Google SERPs with ColdFusion

Code:
[COLOR=#333333][COLOR=#808080][I]<!---  We only need the domain name without the http://www. --->[/I][/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]<cfset[/COLOR] siteurl [COLOR=#0000ff]=[/COLOR] [COLOR=#009900]"jasonbartholme.com"[/COLOR][COLOR=#990000]>[/COLOR][/COLOR] [COLOR=#333333][COLOR=#808080][I]<!---  Regular expression which matches the pattern to determine count--->[/I][/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]<cfset[/COLOR] googleregex [COLOR=#0000ff]=[/COLOR] [COLOR=#009900]'<font size=-1>[/COLOR][/COLOR]Results [\s\S]*? of about [COLOR=#333333][COLOR=#000000][B]<b>[/B][/COLOR][/COLOR]([\s\S]*?)[COLOR=#333333][COLOR=#990000]<[/COLOR][COLOR=#0000ff]/[/COLOR]b&[COLOR=#0000ff]gt[/COLOR];[/COLOR] for'> [COLOR=#333333][COLOR=#808080][I]<!--- useragent is required because the page will not "get" properly otherwise --->[/I][/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]<cfhttp[/COLOR] url[COLOR=#0000ff]=[/COLOR][COLOR=#009900]"http://www.google.com/search?q=site%3A#siteurl#"[/COLOR]		[COLOR=#0000ff]method[/COLOR][COLOR=#0000ff]=[/COLOR][COLOR=#009900]"get"[/COLOR]		resolveurl[COLOR=#0000ff]=[/COLOR][COLOR=#009900]"false"[/COLOR]		useragent[COLOR=#0000ff]=[/COLOR][COLOR=#009900]"#cgi.http_user_agent#"[/COLOR][COLOR=#990000]>[/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]</cfhttp>[/COLOR][/COLOR] [COLOR=#333333][COLOR=#808080][I]<!---  Trims the whitespace in the content, and check for our regex pattern --->[/I][/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]<cfset[/COLOR] sdoc [COLOR=#0000ff]=[/COLOR] [COLOR=#0000ff]trim[/COLOR][COLOR=#0000ff]([/COLOR]cfhttp.filecontent[COLOR=#0000ff])[/COLOR][COLOR=#990000]>[/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]<cfset[/COLOR] resu[COLOR=#0000ff]lt[/COLOR] [COLOR=#0000ff]=[/COLOR] [COLOR=#0000ff]refindnocase[/COLOR][COLOR=#0000ff]([/COLOR]googleregex,sdoc,[COLOR=#ff0000]1[/COLOR],[COLOR=#009900]"true"[/COLOR][COLOR=#0000ff])[/COLOR][COLOR=#990000]>[/COLOR][/COLOR] [COLOR=#333333][COLOR=#808080][I]<!---  cftry/cfcatch to see if refindnocase() returned a result --->[/I][/COLOR][/COLOR][COLOR=#333333]&[COLOR=#0000ff]lt[/COLOR];cftry&[COLOR=#0000ff]gt[/COLOR];[/COLOR]	[COLOR=#333333][COLOR=#990000]<cfset[/COLOR] resu[COLOR=#0000ff]lt[/COLOR]count [COLOR=#0000ff]=[/COLOR] [COLOR=#0000ff]replace[/COLOR][COLOR=#0000ff]([/COLOR][COLOR=#0000ff]mid[/COLOR][COLOR=#0000ff]([/COLOR]sdoc,resu[COLOR=#0000ff]lt[/COLOR].pos[COLOR=#0000ff][[/COLOR][COLOR=#ff0000]2[/COLOR][COLOR=#0000ff]][/COLOR],resu[COLOR=#0000ff]lt[/COLOR].[COLOR=#0000ff]len[/COLOR][COLOR=#0000ff][[/COLOR][COLOR=#ff0000]2[/COLOR][COLOR=#0000ff]][/COLOR][COLOR=#0000ff])[/COLOR],[COLOR=#009900]','[/COLOR],[COLOR=#009900]''[/COLOR],[COLOR=#009900]'ALL'[/COLOR][COLOR=#0000ff])[/COLOR][COLOR=#990000]>[/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]<cfcatch[/COLOR] [COLOR=#0000ff]type[/COLOR][COLOR=#0000ff]=[/COLOR][COLOR=#009900]"any"[/COLOR][COLOR=#990000]>[/COLOR][/COLOR]	[COLOR=#333333][COLOR=#990000]<cfset[/COLOR] resu[COLOR=#0000ff]lt[/COLOR]count [COLOR=#0000ff]=[/COLOR] [COLOR=#ff0000]0[/COLOR]&[COLOR=#0000ff]gt[/COLOR];[/COLOR][COLOR=#333333][COLOR=#990000]</cfcatch>[/COLOR][/COLOR][COLOR=#333333][COLOR=#990000]</cftry>[/COLOR][/COLOR] [COLOR=#333333][COLOR=#808080][I]<!---  display our result --->[/I][/COLOR][/COLOR]Pages indexed: [COLOR=#333333][COLOR=#990000]<cfoutput>[/COLOR][/COLOR][COLOR=#0000ff]#resu[COLOR=#0000ff]lt[/COLOR]count#[/COLOR][COLOR=#333333][COLOR=#990000]</cfoutput>[/COLOR][/COLOR]

Original Post: Scraping Google SERPs with ColdFusion
 
Advanced Date Parsing with ColdFusion

Advanced Date Parsing with ColdFusion

This is helpfull if you scrape an RSS Feed, and need to format the date, to your own likings. *hint* For instance , you want to take the RSS Feed date, get the #month#, #date#, then create a page, based on that date ..

/#month#/#date#/#year#/#rsstitle#.cfm

Anyway, normal parsedate() would work, however, this puts in concideration time zones ! ...


Code:
<cfset date = GetHttpTimeString()>
<cfset formatter = CreateObject("java", "java.text.SimpleDateFormat")>
<cfset formatter.init("EEE, dd MMM yyyy HH:mm:ss Z")>
<cfset parsePosition = CreateObject("java", "java.text.ParsePosition")>
<cfset parsePosition.init(0)>
<cfset newDate = formatter.parse(date, parsePosition)>
<cfoutput>
GetHttpTimeString = #date# <br />
SimpleDateFormat = #newDate# <br />
ParseDateTime = #ParseDateTime(date)#
</cfoutput>

Original Post: Advanced Date Parsing with ColdFusion
 
Why do people assume that's my face? Sorry, let me rephrase that. Why do all the retarded people assume that's my face? For your information, that is the face of one beautiful Jeremy Estes, our resident party-man, ladies-man, and let's not forget the Vatican's official affiliate marketer.
 
I just sayd it cause ur retarted for leaving that comment. If you don't use CF than that shit is useless to you, so stay the fuck out of the thread, or at least don't say shit. Stick with ur cobol and fortron threads.
 
Lol. I was merely saying the arguing here is retarded. In fact, I was going to give you +rep for at least going out of your way to post all these snippets, even if nobody will use them. But since you're being such a cunt, whoops! My finger slipped onto the negative rep button. :)
 
Oh by the way. Your negative rep shows up as nothing more than a grey dot for me, whereas mine should cut your total rep in half. :)
 
Status
Not open for further replies.