If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
I recently worked on a project that allowed users to upload images and I then needed to create different versions of the image... a 1200 x N, 430 x N, and 75x75... wait it has to be square!? Yeah that was my first thought, nah that won't work
What about stretching it?

Nope that looks like junk
What about white bars ALA Your DVD player?

Image is too small and they want the image to fill up the whole square.
hmm how about a nice sized-down-then-chopped image?

yeah that would look cool.
So how do we do it?
First we need to read the image from the upload and put it into a variable
Next we want to create an image that is 1200xN and an image that is 430xN and write it to our image directory.
The fun part comes next. We want to create the thumbnail and do all kinds of math to figure out how to crop. That is where the "FromX" and "FromY" variables comes in. It figures out where the upper left hand corner is then it walks its way in to 38 pixels and does a crop. This is how we now if it is portrait or landscape and where to crop it. After that we save the image and we are done!
Nice easy way to create cool looking square thumbnails.
Just to point out anything passed 114 x 114 would not resize correctly. I solved this by the following…
<cfset mysum = myImage.Width / 38?
My math is not the best but working out how many times 38 goes in to the width means I can resize the thumb dynamic to what I want.
Hey Glyn, submit me the via my contact us form and I will post it as an edit. Thanks!
I’ve modified your code to make it work with all possible thumbnail sizes by doing the following:
Where thumbnailWidth is the max width you want (i.e. 75, 150, 114).
D’OH! Let me try that code post again…
<cfset offSet = ceiling( thumbnailWidth / 2 ) />
Also, offSet is your fromX or fromY.
Thanks Demian! It’s nice to know that old posts written months ago are still helpful to people!