in Education by
I'm using this code to merge text with an image and it's working fine. But when I use this code with Facebook app, it doesn't show any output. Can anyone please help me sorting out the problem? As far as I believe, the problem is with this line: header("Content-Type: image/jpeg"); When I remove it, it shows some messed up output. <?php header("Content-Type: image/jpeg"); $im = ImageCreateFrompng("jump_empty.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'ambient.ttf', "hellooo"); Imagejpeg($im, '', 100); ImageDestroy($im); ?> Here is the code I'm using for Facebook app: <?php include_once 'facebook.php'; include_once 'config.php'; $facebook = new Facebook(array( 'appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_SECRET_KEY, 'cookie' => true, 'domain' => '_____' )); header("Content-Type: image/jpeg"); $session = $facebook->getSession(); if (!$session) { $url = $facebook->getLoginUrl(array( 'canvas' => 1, 'fbconnect' => 0, 'req_perms' => 'read_stream,publish_stream' )); echo "top.location.href = '$url';"; } else { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); echo "Hey " . $me['name'] . "!
"; $im = ImageCreateFrompng("jump_empty.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'ambient.ttf', 'hello'); Imagejpeg($im, '', 100); ImageDestroy($im); } catch (FacebookApiException $e) { echo "Error:" . print_r($e, true); } } ?> JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The problem is that you are trying to deliver two different content types in one page. You cannot send the image/jpeg header, telling the browser to expect an image, and then send js and or html. To accomplish this you should use two php scripts. One that sends the image/jpeg header and generates the image as you have in your first code block, and a second with normal headers that includes the first as the src of an image tag. If you want your image to be dynamic you could pass parameters to the image script as you would any php page. Your first script lets call it image.php would then be: <?php header("Content-Type: image/jpeg"); $im = ImageCreateFrompng("jump_empty.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'ambient.ttf', "hellooo"); Imagejpeg($im, '', 100); ImageDestroy($im); ?> Just as you had it. You second script would be: <?php include_once 'facebook.php'; include_once 'config.php'; $facebook = new Facebook(array( 'appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_SECRET_KEY, 'cookie' => true, 'domain' => '_____' )); $session = $facebook->getSession(); if (!$session) { $url = $facebook->getLoginUrl(array( 'canvas' => 1, 'fbconnect' => 0, 'req_perms' => 'read_stream,publish_stream', )); echo "top.location.href = '$url';"; } else { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); echo "Hey " . $me['name'] . "!
"; echo 'image'; } catch (FacebookApiException $e) { echo "Error:" . print_r($e, true); } } ?> Hope this helps.

Related questions

0 votes
    I'm trying to use the mail() function on my computer so I can test the web application's system ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    My code cannot display the permission dialog when a user connect to my Facebook application. Instead of the login page, I ... getLoginUrl(array( 'scope' => 'publish_stream', )); }...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have been using php-sdk to connect to facebook for a while and I never had any problems, but ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have the following code : curl -X PUT -u ":" \ -H "Content-Type: application/json" \ --data '{"alias": "myalias"} ... and i don't know what is the problem. this is what i tried...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    You are working with this XML code snippet from the XML document cars.xml. You need to return the information about the cars ... D.doc("cars.xml")/cars/car[integer(year) > 2000]...
asked Mar 10, 2023 in Technology by JackTerrance
0 votes
    If the code is stored in the external file, which of the following function is used to call them to a ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Commiting a code change, when the inspection fails , is perfectly fine as the code logic is working fine anyway (i)False (ii)True...
asked Oct 5, 2020 in Technology by Editorial Staff
0 votes
    I've set up a simple app to run in a page tab. After authorizing the use of the app, just for ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    FQL statement has executed and array object has been passed to $fqlResult successfully. However, I'm unable ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    httr package does not work well with facebook and twitter API. (a) True (b) False The question was ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    I want to click on group add button of Facebook, but I have not found it possible using an xpath. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a Facebook Like button implementation which is rendering fine in all browsers desktop and mobile. But ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Facebook Adverts is an advertising platform that can deliver ads on _____________. (1)Instagram (2)Both Facebook and Instagram (3)Facebook...
asked May 17, 2021 in General by JackTerrance
0 votes
    Can any body help me find out, why this link(webRTC example) http://goo.gl/PNMSII not working on ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
...