Tuk Posted February 22, 2010 Share Posted February 22, 2010 I'm having an issue with dynamic image creation. I know what my problem is so I'm just wondering if there's a way to make it work, or if I'm out of luck. Basically I have an image and I want to display a dynamic string on it. I've looked up tutorials, etc, and eventually I got it working, except the string isn't showing, and I think it's because it's a variable. I got it to work perfectly by putting a static word as the string ('hello'), but when I changed that to a variable, the main image shows up but with no text on it. I believe my problem is that the variable is obtained by using $_GET then a select query to get the information from the database for that particular user. I have the dynamic image set up in a separate file (file names have been changed, but I know those aren't the problem): <? $image = imagecreatefrompng("image url"); $textcolor = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); imagestring($image, 1, 10, 10, "$variable", $textcolor); header('Content-type: image/png'); imagepng($image); ?> I then call on the image with this, in the file I want the image to be displayed in...: <img src=imagefile.php> So basically, here's my problem... I need to use a select query to get the proper information for $variable, but since the dynamic image file needs to define itself as an image/png content-type, adding in any other script such as a query will cause the image to break... I can't include anything for the same reason... When I was looking up how to do a dynamic image in general, the only examples I found had static strings, but I kept reading that you could use a variable instead... but now I'm trying and it's not working. :/ As a note, I tried doing the select query in a separate file and including it, and the image broke again. Any thoughts? Thanks. Link to comment https://forums.phpfreaks.com/topic/193000-dynamic-image-problem/ Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 Is there any reason why you have $variable in " " in your imagestring() call, and what happens if you remove them? Link to comment https://forums.phpfreaks.com/topic/193000-dynamic-image-problem/#findComment-1016416 Share on other sites More sharing options...
Tuk Posted February 22, 2010 Author Share Posted February 22, 2010 Nothing happens when I remove them. I am almost positive the problem I described is why this isn't working. I don't think the quotes have anything to do with it. Link to comment https://forums.phpfreaks.com/topic/193000-dynamic-image-problem/#findComment-1016421 Share on other sites More sharing options...
JAY6390 Posted February 22, 2010 Share Posted February 22, 2010 If it works with a static string but not a variable then the variable isn't being set. A function will not stop working based on if you pass a string or a variable with the same string on it. Firstly you need to learn how to make valid HTML <img src="imagefile.php" alt="Dynamic Image" /> Secondly you say you are passing the text via $_GET but that is not the case. If you want to pass it via $_GET you would need imagefile.php?var_name=some_value and then use $_GET['var_name'] in your imagefile.php script to get the data and use it Link to comment https://forums.phpfreaks.com/topic/193000-dynamic-image-problem/#findComment-1016424 Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 Anywhere you can use a literal string, you can also use a string variable. As you will see from the examples in the manual at http://php.net/manual/en/function.imagestring.php a string variably is often used. Link to comment https://forums.phpfreaks.com/topic/193000-dynamic-image-problem/#findComment-1016428 Share on other sites More sharing options...
Tuk Posted February 22, 2010 Author Share Posted February 22, 2010 I wasn't clear enough in my description of how it's working, I suppose, as some of what you said doesn't apply. I also changed the names of files, etc. However, as I was typing this reply, I had an epiphany, and it worked. Link to comment https://forums.phpfreaks.com/topic/193000-dynamic-image-problem/#findComment-1016438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.