Tuesday, April 19, 2011

Create dynamic images in php

Simple task: user input as string to be applied with a custom font on a given image.

You can view a demo here.

  • the font size is calculated depending on image's height;
  • the number of characters displayed on a row is calculated depending on image's width and calculated font size;
  • the text is split to pe displayed on multiple lines;
  • user can pick the text color on image;
  • the text has transparency;
  • the resulting picture is provided for download.
If you have suggestions or need the code, feel free to email me (write a suggestive email subject)

Friday, April 15, 2011

me and my facebook(s) - part 2

Friday evening, at the office, waiting for a server to "get real"...it won't
Anyway, the last weeks I had to do some stuff with the new Facebook API (which is really ok, I suppose...only it is not documented in a very efficient manner, so I end up spending hours for some simple tasks).

So, 2 easy hints if you want to upload a picture with the API (you will find tones of examples of code of how-to, the actual algorithm, using a PHP library which wraps the requests in a more elegant way, or directly with CURL):
1.For upload need special permissions - main permissions: read_stream, publish_stream, photo_upload, user_photos
2. Before the upload code you need to set the upload file support
Now, some other things I had to do were 1. to save a picture (from the disk) to a Facebook user Profile album and 2. eventually open it so the user has the possibility to set it as his/her Profile Picture. The first thing is possible if the user already has a Profile Picture album. Otherwise you can not create from API that type of album (with type = 'profile' ). If the user did not have a profile picture yet it will be saved in an album with the application name.
The second part is alittle tricky, because Facebook would not allow an application to mess around with stuff which is part of user's privacy - such as the profile picture, so all you can do is open a new window with the saved picture in Facebook and let the user decide if he/she wants that picture to be his/her profile picture. How to do that? The action of saving a picture to profile/or_not_profile_yet album will return you the ID of the picture (in the Facebook graph), say it's $pid. The url where the user can see the picture and take the decision I've talked above looks something like this: