Jump to content

Recommended Posts

I am trying to assign a variable "$fullname" from database, and then output that variable text content to png. The $fullname script works if I echo it to the screen. And the text-to-png part works if I either manually declare the text to be transformed or if I manually declare the value of the $fullname variable (see commented test in code). But if I use two together to dynamically set the value of the $fullname variable, it does not work. Is there something glaring and obvious I am missing?

I know the query is not pretty. The DB schema I am working with is ... bad. But it is what I have to work with right now.

Here's my code:
I was unable to post code, so check it here:
[a href=\"http://bogobug.com/uname_to_png.txt\" target=\"_blank\"]http://bogobug.com/uname_to_png.txt[/a]
Link to comment
https://forums.phpfreaks.com/topic/5115-variable-text-to-png/
Share on other sites

If you want tp create them on-the-fly then save this bit in a separate script, say, "imagetext.php"

[code]<?php
$fullname = $_GET['fn'];

// create an image with width 'x', height 'y'
$image = imagecreate(200, 100);

// create a background color and then set it to transparent
$background = imagecolorallocate($image, 255, 255, 255);
ImageColorTransparent($image, $background);
ImageInterlace($image, false);

// set black color for the text
$black = imagecolorallocate($image, 0, 0, 0);

// write the variable string to the image
// the top left of the text is at the position (10, 2)
imagestring($image, 4, 10, 2, $fullname, $black);

// tell the browser what we're sending it
Header('Content-type: image/png');

// output the image as a png
// imagepng($image);
imagepng($image);

// tidy up
imagedestroy($image);
?>[/code]

And in main script, to display the image

[code]echo "<IMG src='imagetext.php?fn=$fullname'>";[/code]
Link to comment
https://forums.phpfreaks.com/topic/5115-variable-text-to-png/#findComment-18300
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.