Search code examples
facebookfacebook-graph-apicoldfusionresizecfimage

resize facebook profile image


Is there any way to resize the profile picture you retreive from the graph api url https://graph.facebook.com/profileid/picture?type=square?

I know about the different types you can call. But I need to resize the image server side, stored in a cfimage tag, so I can display it with the correct size.

Unfortunately, I'm unable to find a way to get to the actual image, because the url doen't get resolved when putting it as source of a cfimage tag.


Solution

  • Try something like this:

    <cfhttp
        url="https://graph.facebook.com/#USER_ID#?type=square&fields=picture"
        method="get"
        getasbinary="yes"
        result="pic">
    
    <cfset img = ImageNew(pic.FileContent)>
    <cfif isImage(img)>
        <cfimage action="resize" source="#img#" width="50">
        <cfimage action="writetoBrowser" source="#img#">
    <cfelse>
        <img src="Default.png"/>
    </cfif>
    

    Alternatively, you may want to save the image to disk.