0

I want a help,I created a facebook app using php gd.The program is when user open the app a image will appear.The image contains the username of the user,the profile pic and random generated nick name.Iam saving the output image to the server as resized.jpg and post that image to the users wall using facebook graph. The problem is when 2 users use the app at same time,the output varies. How to generate image to each user without saving it to the server and post to facebook. now iam using html img tag to display the image in app..

Jijo John
  • 1,375
  • 9
  • 21
  • _“I want a help”_ – to get help here, please make up a better title for your question first. _“Php gd help here”_ does say nearly nothing about your actual problem – which is f.e. bad for people finding this later using search, because they will have no idea from the title alone if your question and the possible answers will be worth looking at or not. – CBroe Sep 24 '12 at 11:35

2 Answers2

0

Answer is quite simple: your image file name must have different names per user. If you have user id in $uid variable,why don't you save target file as:

imagejpeg( $rImg, "resized".$uid.".jpg" );

This way you'll have different images per user.

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68
0

Rather than saving the file to your server as "resized.jpg", what you want to do is to output the generated image directly to the user. From http://php.net/manual/en/function.imagejpeg.php it says to set filename to NULL, which causes the output to be sent to the user instead of to a file. Note: you may also need to set the correct Content-Type using the header function.

This method is an alternative to Tomasz's. With his method, each image is cached on your server. With mine, the image is generated each time the page is requested. Here is an example showing the difference:

<img src="http://example.com/resized1234.jpg"> #1234 is the user's id
<img src="http://example.com/generate-image.php?uid=1234">

In your case, you said you are posting the image directly to Facebook, so I would advise my method, as Facebook will store its own copy of the image if you post it on their site, and won't need to be cached. Also, you won't have a other user's images piling up on your site.

Let me know if you need me to clarify anything in my answer!

drdrez
  • 921
  • 1
  • 7
  • 16