Jump to content

image creation with added text from url(get) problem


jonaHill87

Recommended Posts

Hi all. I don't know much this function so I'll try to be as clear as I can. I'm trying to create an image from a png file with text from an url(using get) over top of the image. I found this example on the php.net but I just can't to get it to work, I just keep getting a blank screen. http://www.php.net/manual/en/ref.image.php. You need to scroll down a bit, it's example 1.

 

I'm sending my text data from one page that looks like this:

As you can see I'm getting my text from a database but that's not the problem.

<?php
$query = "SELECT ButtonText FROM ButtonMenu";
$result = mysql_query($query);
while ($query_data = mysql_fetch_row($result)) {
foreach ($query_data as $entry) {
echo "<img src='page2.php?text=$entry' />";
}
}
?>

 

to another page that looks like this. It contains the example code and I have added comments to the code lines that I'm not familiar with. Thanks to any1 that can help. Btw, my button.png is in the same dir as my php files.

<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("Button.png");
$black = imagecolorallocate($im, 0, 0, 0); //I don't need any color so can I remove this line?
$px = (imagesx($im) - 7.5 * strlen($string)) / 2; // not sure what's going on in this line.
imagestring($im, 3, $px, 9, $string, $black); //would i need to remove anything here?
imagepng($im);
imagedestroy($im);
?>

 

 

 

Link to comment
Share on other sites

Hi,

 

<?php

header("Content-type: image/png");

$string = $_GET['text'];

$im = imagecreatefrompng("Button.png");button.png

 

$black = imagecolorallocate($im, 0, 0, 0); //I don't need any color so can I remove this line?

 

YES YOU CAN REMOVE THIS LINE.

 

$px = (imagesx($im) - 7.5 * strlen($string)) / 2; // not sure what's going on in this line.

 

THIS CALCULATE WHERE TO SHOW YOUR STRING ON IMAGE ( X )

 

 

imagestring($im, 3, $px, 9, $string, $black); //would i need to remove anything here?

 

NO YOU DON'T HAVE TO CHANGE ANYTHING HERE IS $BLACK IS NULL OR EMPTY IT WILL TAKE IT AS WHITE COLOR.ALL FIELDS ARE MANDATORY NO OPTIONAL SO YOU HAVE TO GIVE THESE NUMBER OF PARAMETER IN imagestring() function.

 

imagepng($im);

imagedestroy($im);

?>

 

let us know if things are not solved.

Link to comment
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.