Heroku create image

Go To StackoverFlow.com

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.

2012-04-04 20:45
by sapphire
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 2012-04-05 05:19


0

Call the image like so:

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

Set the image height / width accordingly.

2012-04-04 20:53
by Blake
imagepng($im); should return image to browser - sapphire 2012-04-05 15:27
This is php app in action on my server: http://test.funnyvideosonnyoutube.com - sapphire 2012-04-05 15:28
Source is located here: http://test.funnyvideosonnyoutube.com/source.tx - sapphire 2012-04-05 15:28
Works just fine for me - Blake 2012-04-05 15:31
It works fine on my server, but not on heroku. This is just demonstration(http://test.funnyvideosonnyoutube.com/ - sapphire 2012-04-05 16:04


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.

2012-04-04 20:55
by Jody
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 ap - sapphire 2012-04-05 15:25
You could try writing to S3 - then give the download link to there - Jody 2012-04-09 23:38
Ads