Horror Profile Facebook application source code released
Horror Profile is a Facebook application I developed a month ago.
Now it’s time to release the source code. You will find some useful tips about dynamic image creation with php.
If you are absolutely new to Facebook applications, I suggest you to read “Developing a Facebook Application for absolute beginners” posts 1, 2, 3, 4 and 5.
The idea is simple: placing the profile picture in a mirror (that is a transparent PNG image) and writing the user first name as big as I can.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | <?php // this is the core function. // giving an user id, a text (user first name) and an url (path to the user profile picture) // creates the horror picture function create_pic($id,$text,$url){ // creation of a new image, the final one $im = imagecreatetruecolor(500,500); // importing profile picture $profile = imagecreatefromjpeg($url); // importing transparent mirror image $mirror = imagecreatefrompng("mirror.png"); // retrieving profile picture size $sizes = getimagesize($url); $x_dim = $sizes[0]; $y_dim = $sizes[1]; // mirror transparency is 265x335, so I resize the profile picture // to fit this size, keeping widht/height ratio if($x_dim<265 or $y_dim<335){ $mult = max(265/$x_dim,335/$y_dim); $final_x = $x_dim*$mult; $final_y = $y_dim*$mult; } // pasting the resized profile picture on the final image imagecopyresampled($im,$profile,250-$final_x/2,300-$final_y/2,0,0,$final_x,$final_y,$x_dim,$y_dim); // pasting the mirror on the final image imagecopyresampled($im,$mirror,0,0,0,0,500,500,500,500); // creating some colors $color = imagecolorallocate($im, 125, 0, 0); $shadow = imagecolorallocate($im, 0, 0, 0); // this is the path of the font I am using $font = "SF Gushing Meadow.ttf"; // starting at font size 0 $size = 0; // boolean variable to determine if the font fits on the picture $it_fits = true; // increasing font zize by one unit until it won't fit anymore do{ $last_dim = $dim; $size++; $dim = imageftbbox($size, 0, $font, $text); if($dim[4]-$dim[6]>500){ $it_fits=false; } } while($it_fits); // adding the text $center = floor((500-$last_dim[4]+$last_dim[6])/2); imagettftext($im, $size-1, 0, $center, $last_dim[7]*-1+10, $shadow, $font, $text); imagettftext($im, $size-1, 0, $center-1, $last_dim[7]*-1+9, $color, $font, $text); // saving the image imagejpeg($im,"temp/".$id.".jpg",80); // freeing memory imagedestroy($im); imagedestroy($profile); imagedestroy($mirror); } ?> <script> function grant() { document.setLocation("http://apps.facebook.com/horror_name/?pub=1"); } </script> <?php require_once "facebook.php"; $appapikey = "xxxxx"; $appsecret = "xxxx"; $facebook = new Facebook($appapikey, $appsecret); $user_id = $facebook->require_login(); $my_array = $facebook->api_client->users_getInfo($user_id,"first_name,pic_big"); // getting user name and profile picture $text = $my_array[0][first_name]; $pic = $my_array[0][pic_big]; // core function: creation of the horror picture create_pic($user_id,$text,$pic); $has_permission = $facebook->api_client->users_hasAppPermission("photo_upload"); if($has_permission and $_GET[pub]){ $response_array = $facebook->api_client->photos_upload("temp/".$user_id.".jpg", "", "Created with http://apps.facebook.com/horror_name/", $user_id); } ?> <style> <?php echo htmlentities(file_get_contents("style.css", true)); ?> </style> <h2>Hello <fb:name uid="<?php echo $user_id; ?>" useyou="false" linked="false" firstnameonly="true"></fb:name>, let's see how horrific is your profile:</h2> <div class = "image"><img src = "http://www.gamemummy.com/facebook/horror_name/temp/<?php echo $user_id; ?>.jpg" /></div> <?php if(!$has_permission){ ?> <div class = "publish"><fb:prompt-permission perms="photo_upload" next_fbjs="grant()">Scare your friends!! Publish this horrific photo on your profile!!</fb:prompt-permission></div> <?php } else { ?> <?php if(!$_GET[pub]) { ?> <div class = "publish"><a href = "http://apps.facebook.com/horror_name/?pub=1">Scare your friends!! Publish this horrific photo on your profile!!</a></div> <?php } else { ?> <div class = "publish">PHOTO PUBLISHED</div> <?php } ?> <?php } ?> <div class = "ad"><fb:iframe src = "http://www.gamemummy.com/facebook/horror_name/ad.html" width = "728" height = "90" frameborder = "0"></fb:iframe></div> <ul> <li>Concept and coding by <a href = "http://emanueleferonato.com/" target = "_blank">Emanuele Feronato</a></li> <li>Picture by <a href = "http://aliceindeadland.deviantart.com/" target = "_blank">AliceinDeadLand</a></li> </ul> |
Hope you will make something decent out of it…
















(8 votes, average: 3.63 out of 5)









This post has 21 comments
Sergey
Emanuele, do you know how make your flash applications running inline on Facebook?
arxanas
I’ve been wondering how PHP image creation worked…
Emanuele Feronato
you can do some decent image manipulation using GD libraries
Cris
I am trying to do something similar, but i think that i have to config my php server, but i don´t know how.
I have this error in Facebook:
PHP Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: URL file-access is disabled in the server configuration in E:…\index.php on line 6 PHP Warning: imagecreatefromjpeg(http://profile.ak.fbcdn.net/v22941/664/25/q878789797987978.jpg) [function.imagecreatefromjpeg]: failed to open stream: no suitable wrapper could be found in E:…\index.php on line 6 PHP Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in E:\…\index.php on line 8 PHP Warning: getimagesize(http://profile.ak.fbcdn.net/v22941/664/25/q……978.jpg) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in E:\…\index.php on line 8 PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in E:\…\index.php on line 18 PHP Warning: imagejpeg() [function.imagejpeg]: Unable to open ‘temp/100000378738508.jpg’ for writing: Permission denied in E:\…\index.php on line 42 PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in E:\…\index.php on line 45
David Salo
Do you know to suggest invites once the my image is published?.I mean one thing that some apps do, when you publish the thing they bring you to alist of friends and you chose many of them to invite.
Ze Ferreira
here it is my 1st FB app inspired in your Horror Profile application.
Be free to feedback it.
http://apps.facebook.com/xmasprofilepic/
Popoy
Hi Ze Ferreira,
Nice app! it is possible to see the source code for it? :-) especially embedding of Google Adsense code.
Ze Ferreira
Hi Popoy,
to embedding adsense is simple and you have it her in the code of horror profile line 125 is one iframe and in the ad.html is the code of the adsense, easy. all the code is similar to horror profile with some variations.
Malshan Fonseka
how to change the MIRROR.PNG
Malshan Fonseka
but PUBLISH is NOT WORKING how to fix it
Eric
Hi,
Could u possibly create a flash tutorial almost similar to Horror Profile??
The problem i faced is tat i do not know how to show facebook profile image and name in Flash.
The method i using is FBML, PHP and AS3.
THankalot if u have the time to create the tutorial.
JaJa
PUBLISH is NOT WORKING how to fix it
Jack
Fatal error: Call to undefined method Facebook::require_login() in /home/a5358356/public_html/horrorprofile/index.php on line 87
How to solve?
marciorosa.org » Horror Profile Facebook application source code released - Complete listing Tools and resorces for the ultimate web developer
[...] in a mirror (that is a transparent PNG image) and writing the user first name as big as I can. Read more by Emanuele [...]
Christian Scholz-Flöter
Is it still sound advice to suggest reading the “Developing a Facebook Application for absolute beginners” posts?
I am afraid that I am very suspicious because several attempts to get the simplest thing done in my own FB app have failed so far. I mean, you would delete the article when it becomes invalid, right? Or add a comment that what you are writing about is not valid any longer?
My impression is that several developers have shared their Facebook related findings time and time again in the last three years. But trying them today has not worked for me in even one instance. Maybe it is because the articles contents I have read were true at the point of writing, but are showing techniques which today are invalid…
Thanks for sharing!
renan
dont work for me all times tell me errors…..
please post correct code
mike
It is great app but I’m geting error:
Fatal error: Call to undefined method Facebook::require_login() in /public_html/horrorprofile/index.php on line 87
Can someone help me with this?
Thanks,
Mike
mike
I’m interested in buying a working version of this script. Please contact me. Thanks.
mike
If you would like to sell your script/code (xmasprofilepic) please contact me. Thanks.
Danny
I have wondered how images were created server-side since the beginning of time, great tutorial.
Vivek Creations
Check my blog for more about application making of facebook.
Your source code have error :)