[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CFImage Center and Crop Question

Posted on 2011-04-28
2
Medium Priority
?
415 Views
Last Modified: 2012-05-11
I am grabbing images when aggregating a blog feed.  For the most part this works just fine:

<cfset theImage = ExpandPath(request.base_relative_url & '/images/uploads/news_images/' & variables.tmp_filename)>
                                                                                                      
<cfset myLargeImg = imageNew(theImage)>
<cfset imageCrop(myLargeImg, (myLargeImg.width/2) - (580/2), (myLargeImg.height/2) - (220/2), 580, 220)>
<cfimage source="#myLargeImg#" action="write" destination="#ExpandPath(request.base_relative_url & '/images/uploads/news_images/'& "large_" & variables.tmp_filename)#" overwrite="yes">

I think the problem I am having is that if the width of the actual image is say only 500px wide, it doesn't do anything at all.

My goal is to make sure that no matter what image is grabbed, I want to create an image that is 580x220 and have whatever it is in the middle of the image.  Right now it seems to be skipping the images if they are smaller.

Any ideas on how I can make sure an image is generated with some part of the the grabbed image and have it be 580x200, no matter what.

Thanks
0
Comment
Question by:theideabulb
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 35486147
Right now it seems to be skipping the images if they are smaller.

I don't know about skipping, but definitely weird results since your x/y coordinates could end up negative (ie outside of the visible area).

how I can make sure an image is generated with some part of the the grabbed image and have it be 580x200, no matter what.

Verify the image is at least 580/220 before using the imageCrop logic. If it's not, decide how you want to handle it.  You could resize it to 580/220 or ... paste the smaller image onto a blank canvas that's the right size.   All depends on what you want.
0
 

Author Closing Comment

by:theideabulb
ID: 35488751
yes, i got the image info and did an if statement

<cfif blogLargeImg.width gte 580 AND  blogThumbImg.height gte 220>
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question