Jump to content

dynamically generate an image w/text from database


fat creative

Recommended Posts

I am trying to code the following:  when you mouse over a word, an image will popup.  Obviously I can do this with javascript no problem. But I need a standard background image to always appear and then the text on the image to change based on whats in the database. For example, if clientid=1, then put the client name, address, etc on an image. If clientid=2, put the new client name, address, etc on the same image.  Can anyone offer any suggestions? I have seen code to change the background color of a square and then I can make my php statements to retrieve the text I need, I can do a javascript onmouseover, but I can't seem to get that to work with a php file. I'm just not sure which way to go from here.  ANY help would be appreciated!

Link to comment
Share on other sites

I read that post before creating my post.  Unless I'm totally missing it, it seems to be doing text on a square with the background colors changing. I've seem lots of tutorials on that, but it's not quite I'm needing. And unfortunately, I'm quite a newbie and I'm not sure what to change to get what I need. 

Link to comment
Share on other sites

Hmmm...

 

I quickly scanned the tut, it does seem to allow you to...

 

1. Determine the width of the box (image) using wordwrap (length will then be calculated based upon the text content)

 

2.  Choose what back ground color and folt color will be.

 

3. Choose what font and size you desire

 

 

Link to comment
Share on other sites

  • 5 weeks later...

Thank you for the info. I have spent the last few weeks trying to get this to work with no avail.  I've gone through this tutorial again and I just don't see it as what I am really looking for.  What I will have is a database with name and special and featured (yes/no). If featured is a yes, then the name appears. When you mouseover the name, an image will appear and will automatically add in the text from the specials column on top of it.  There will be multiple people who are featured = yes and they will each have their own special.  At this point I have nothing.  I thought it would be pretty simple and committed to do it, but now I am clueless how to even get started. ANY suggestions, direction, advice, code, would be appreciated.  Thank you.

Link to comment
Share on other sites

Thank you for the info. I have spent the last few weeks trying to get this to work with no avail.  I've gone through this tutorial again and I just don't see it as what I am really looking for.  What I will have is a database with name and special and featured (yes/no). If featured is a yes, then the name appears. When you mouseover the name, an image will appear and will automatically add in the text from the specials column on top of it.  There will be multiple people who are featured = yes and they will each have their own special.  At this point I have nothing.  I thought it would be pretty simple and committed to do it, but now I am clueless how to even get started. ANY suggestions, direction, advice, code, would be appreciated.  Thank you.

 

It would help if you told us exactly what you are having trouble with. All you say is you can't get that tutorial to work. If you followed the tutorial and get no synax errors when attempting to view your web page post up the code you made so someone can take a look at it and show you what your doing wrong. It seems you expect someone to do this for you which isn't going to happen. If you don't think that tutorial is what you are looking for then I suggest looking at the following.

 

This will teach you how to read information from a database.

http://www.freewebmasterhelp.com/tutorials/phpmysql

 

This will teach you how to generate images using PHP.

http://www.devarticles.com/c/a/PHP/Generating-Images-on-the-Fly-With-PHP/

 

Although like most tutorials these require that you have some programming knowledge if you know absolutely nothing about PHP then I suggest you go here it will teach you the basics.

http://w3schools.com/php/php_syntax.asp

Link to comment
Share on other sites

:-) I wasn't asking anyone to do my work for me.  I was asking for suggestions, directions, advice, code SAMPLES (which I have gotten here before), etc which you have managed to provide. Thank you for that. I didn't copy code here as I have gone through dozens of tutorials and my code changes hour to hour.  I could not get the original tutorial to create an image which is what I meant by I couldn't get it to work. I did get the tutorial you provided to create a square and generate a random image. I'm guessing I can change the random image to something that will get the information from my database by using select statements.  I'm not sure what to change to get the background to be an image, not solid gray and that's what I seem to be missing in all of the tutorials I have found.  I provided all that detail of what I am trying to do as I didn't think I explained myself well enough before and was simply trying to explain better. 

 

Here is my code as it is right now. It's simply the tutorial you provided (again, thank you).

 

<?php header("Content-type: image/jpeg");?>

<?php

//random_number.php

 

$img_number = imagecreate(100,50);

$white = imagecolorallocate($img_number,255,255,255);

$black = imagecolorallocate($img_number,0,0,0);

$grey_shade = imagecolorallocate($img_number,204,204,204);

imagefill($img_number,0,0,$grey_shade);

ImageRectangle($img_number,5,5,94,44,$black);

ImageRectangle($img_number,0,0,99,49,$black);

 

$number = get_random();

Imagestring($img_number,9,30,15,$number,$black);

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

imagejpeg($img_number);

function get_random()

{

 

srand(time());

$max = getrandmax();

return rand(1,$max) + rand(1,$max) ;

}

 

?>

 

This is called from a file with this code:

<img src='http://www.mysite.com/random_number.php' /> THIS ONE IS WORKING

<img onMouseOver="http://www.MYSITE.com/random_number.php">my image is here THIS ONE ISN'T WORKING, I AM STILL TRYING TO FIGURE OUT THE ONMOUSEOVER.

 

So, anyone, thank you in advance for any help. It is truly appreciated.

 

 

 

Link to comment
Share on other sites

Okay, I seem to have half of this working and this is the code if anyone could use it on another project. Seems to work using CSS. I got this code from the CSS library.

/* ========== popup images for coupons =========== */

/*Credits: Dynamic Drive CSS Library */

/*URL: http://www.dynamicdrive.com/style/ */

 

.thumbnail{

position: relative;

z-index: 0;

color: #603814;

text-decoration: italic;

font-size: 14px;

font-weight: normal;

}

 

.thumbnail:visited { /* this is the text color of the visited links*/

position: relative;

z-index: 0;

color: #603814;

text-decoration: none;

font-size: 14px;

font-weight: normal;

}

 

.thumbnail:hover{ /* this is the text color when you hover over it*/

background-color: transparent;

z-index: 50;

text-decoration: none;

font-size: 14px;

color: #a52620;

font-weight: normal;

 

}

 

.thumbnail span{ /*CSS for enlarged image*/

position: absolute;

background-color: #663300;

padding: 5px;

left: -1000px;

/* border: 1px dashed gray;*/

visibility: hidden;

/* display:none;*/

color: #a52620;

text-decoration: none;

font-weight: normal;

}

 

.thumbnail span img{ /*CSS for enlarged image*/

border-width: 0;

padding: 2px;

font-weight: normal;

 

}

 

.thumbnail:hover span{ /*CSS for enlarged image on hover*/

visibility: visible;

top: 0;

left: 60px; /*position where enlarged image should offset horizontally */

font-weight: normal;

}

 

Then I slightly modified the code from the earlier referenced tutorial as follows:

<?php //this is the mouseover.php file

$img_number = imagecreatefrompng ("images/blankcoupon.png");

$number = "this is my new specials text";

Imagestring($img_number,19,50,75,$number,$black);

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

imagejpeg($img_number);

?>

 

These are in two different files and the html code calls the php file as follows:

echo "<a class=\"thumbnail\" href=\"#thumb\">$special<span><img src=\"http://site/~peach/mouseover.php\" /><br /></span></a>";

      echo "</td></tr>\n";

 

The $special variable will display the first 40 characters of text on the site and then the mouseover should display all the text. What's displaying now is the $number text. I tried replacing that with $special, but it didn't show anything. What I can't seem to figure out now is how to pass the $special variable to the mouseover.php file.  I'm not submitting anything like a form, so I don't think a _POST or _GET will work.  It needs to happen on the fly. Does anyone have any thoughts on how to pass this information from the html page to the php page?

 

Thank you so much for any suggestions!

 

 

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.