Skip to content

Commit e9d1cce

Browse files
author
Blair McKenzie
committed
don't pass image through cloudinary if there aren't crops
1 parent 4c4aa3d commit e9d1cce

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/formtools/image.cfc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@
350350
</cfif>
351351
352352
<!--- Copy the source into the new field --->
353-
<cfif len(sourcefilename) and refindnocase("//res.cloudinary.com/",sourcefilename)>
353+
<cfif len(sourcefilename) and (application.fapi.getConfig("cloudinary", "uploadVia", "post") neq "post" or refindnocase("//res.cloudinary.com/",sourcefilename))>
354+
<!--- source=xxx => original file for this image; _source=xxx => temporary variable used for dependant cuts --->
355+
<cfset sourcefilename = replace(sourcefilename,"?source=","?_source=") />
356+
<cfelseif len(sourcefilename) and refindnocase("//res.cloudinary.com/",sourcefilename)>
354357
<!--- source=xxx => original file for this image; _source=xxx => temporary variable used for dependant cuts --->
355358
<cfset sourcefilename = replace(sourcefilename,"?source=","?_source=") />
356359
<cfelseif len(sourcefilename) and application.fc.lib.cdn.ioFileExists(location="images",file=sourcefilename)>
@@ -389,7 +392,7 @@
389392
390393
<cfsetting requesttimeout="120" />
391394
392-
<cfif len(arguments.source) and not refindnocase("//res.cloudinary.com/",arguments.source)>
395+
<cfif len(arguments.source) and application.fapi.getConfig("cloudinary", "uploadVia", "post") eq "post" and not refindnocase("//res.cloudinary.com/",arguments.source)>
393396
<cfreturn super.GenerateImage(argumentCollection=arguments) />
394397
</cfif>
395398
@@ -418,7 +421,7 @@
418421
<cfreturn application.fc.lib.cloudinary.upload(file=arguments.file, publicID=arguments.publicID, transformation=arguments.transformation).urlWithSource />
419422
</cfcase>
420423
<cfcase value="fetch">
421-
<cfreturn application.fc.lib.cloudinary.fetch(file=arguments.file) />
424+
<cfreturn application.fc.lib.cloudinary.fetch(file=arguments.file, cropParams={}) />
422425
</cfcase>
423426
<cfcase value="auto">
424427
<cfreturn application.fc.lib.cloudinary.autoUpload(file=arguments.file) />

packages/lib/cloudinary.cfc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@
436436
</cffunction>
437437

438438
<cffunction name="fetch" output="false" returntype="string" hint="Return cloudinary url of cropped image.">
439-
<cfargument name="sourceURL" required="true" type="string">
439+
<cfargument name="file" required="true" type="string">
440440
<cfargument name="cropParams" required="true" type="struct" hint="width,height,crop,format">
441441

442442
<cfset var stResult = structNew() />
@@ -445,13 +445,19 @@
445445
<cfset var transform = getTransform(argumentCollection=arguments.cropParams)>
446446

447447
<cfset var fetchURL = "#endpoint#/#method#/#transform#/">
448-
<cfset var fileURL =arguments.sourceURL>
448+
<cfset var fileURL =arguments.file>
449449

450-
<cfif (len(fileURL) gt 2 && left(fileURL, 2) == "//")>
451-
<cfset fileURL = "http:" & fileURL>
452-
</cfif>
450+
<cfif (not structKeyExists(arguments.cropParams, "width") or arguments.cropParams.width eq 0)
451+
AND (not structKeyExists(arguments.cropParams, "height") or arguments.cropParams.height eq 0)>
452+
453+
<!--- Don't modify file --->
454+
<cfelse>
455+
<cfif (len(fileURL) gt 2 && left(fileURL, 2) == "//")>
456+
<cfset fileURL = "http:" & fileURL>
457+
</cfif>
453458

454-
<cfset fileURL = fetchURL & urlEncode(fileURL)>
459+
<cfset fileURL = fetchURL & urlEncode(fileURL)>
460+
</cfif>
455461

456462
<cfreturn fileURL />
457463
</cffunction>

0 commit comments

Comments
 (0)