Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How can I use ColdFusion to crop an image?

Use the imageCrop() function.

<!---Read in the image --->
<cfimage action="read" name="myImg" source="foo.jpg">

<!--- Crop to 50x50 pixels starting at X = 1 & Y=1.
<cfset imageCrop(myImg,1,1,50,50)>


This question was written by Jeremy Petersen.
It was last updated on December 10, 2007 at 12:21:59 PM EST.

Categories

Images

Comments

Comment made by Tjarko Rikkerink on December 13, 2007 at 5:30 AM
I think the question should be. How can i crop an image to a square image and retain the complete image within that square. I'm trying this but can't seem to get it working :-(

I want to resize the canvas and not the image. A portrait or landscape that fits in a square and the "empty sides" filled with white as background.


Comment made by Tjarko on December 13, 2007 at 6:15 AM
I actually found the answer to my own question. I will be postig the solution to my problem on www.mximize.com


Comment made by Raymond Camden on December 13, 2007 at 6:51 AM
While your question is valid, there is nothing wrong with the question as is. So I disagree with you that the question "should" be anything else.


Comment made by Tjarko on December 13, 2007 at 7:21 AM
True, I used the wrong words, after trying your code the resulting image was a cutout in the leftupper corner of the image, not the complete image, that wasn't the result I personally was looking for. I will watch my words the next time ;-)


Comment made by Emmet on March 5, 2008 at 2:00 PM
This function is now supported in imageUtils on riaforge.com. Look at AspectCrop()


Comment made by Emmet on March 5, 2008 at 2:02 PM
I was referring to Tjarko's problem.