cul8r cul8r - 11 months ago 72
PHP Question

Share PHP GD-created image on Facebook

Using the PHP GD image library I have successfully outputted an image with text from url parameters (a, b, c).

I need to be able to send these images to the Facebook sharing url so that they can be sent to social media.

However, the sharing link does not seem to accept my php parameters. When I test the url, it pulls the image but does not send any numbers resulting in no text carried through.

Is there a way to save the complete image with parameters and have it sent to the Facebook sharing url? I am doing this through a link embedded in email, so it cannot use anything more complicated than basic HTML.

Answer Source

So I did eventually end up solving this. After giving up on pushing a php image to Facebook with url parameters included, I attempted to place the image into an email. This worked well in nearly every client EXCEPT Gmail. I had to convert the url parameters to get around the Gmail proxy which allowed the image to be displayed AND it also happened to now be usable in the Facebook sharer. Double hooray!

The original way I had it set up was to link the php image with url parameters and use $_GET to place them on the image:


$var1 = $_GET['a'];
$var2 = $_GET['b'];
$var3 = $_GET['c'];

The correct way to do this is the following:


$path = substr($uri, strpos($uri, "a=")); // start your url parameters here
$delim = 'abc=&'; // enter all characters you use in parameters (a, b, c, =, &)
$tok = strtok($path, $delim);
$tokens = array();
while ($tok !== false) {
    array_push($tokens, $tok);
    $tok = strtok($delim);

$var1 = $tokens[0];
$var2 = $tokens[1];
$var3 = $tokens[2];

What this does is look at the url and pull specified characters ($delim) from it to place into an array. Then using what follows those characters, set their value to a token and place that token on the image.

Here is how I set up my php image to display in the email:

<img src=";b=2&amp;c=3">

And my share URL: