0

im using php and heroku to create some images for my facebook app, but the images arent shown, only picture of an broken image is shown. Im using sample code from php tutorial website.

<?php
// Create a 100*30 image
$im = imagecreate(100, 30);

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);

// Output the image
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

The code is in located in /src/texttopic.php Heroku logs shows no errors.

sapphire
  • 21
  • 4
  • Browse to your php file in your webbrowser and save the broken image to a file. Open the file in a text editor and look if you see any error messages. – jgauffin Apr 05 '12 at 05:19

2 Answers2

0

Call the image like so:

<img src="/src/texttopic.php" height="30" width="30">

Set the image height / width accordingly.

Blake
  • 2,294
  • 1
  • 16
  • 24
0

Keep in mind that with heroku, if you have 2 or more web dynos running, the image creation may take place on one dyno, but when you request the image, you may be calling another dyno that does not have that image.

Jody
  • 8,021
  • 4
  • 26
  • 29
  • Yes the problem is that heroku doesnt allow file writing by an app to filesystem. Do you know if there is some /tmp folder which has necesarry permissions to be writable, and then I would use that folder for creating images, as they are created for each user of my facebook app – sapphire Apr 05 '12 at 15:25
  • You could try writing to S3 - then give the download link to there. – Jody Apr 09 '12 at 23:38