vigiw Posted July 6, 2008 Share Posted July 6, 2008 Ok, I have a form which sends to a PHP script--that's all set and working (thanks to the help of forum members here! ). Now, I'm wondering on my PHP page, if I would be able to plot, kind of like a graph, onto an image. Here's what I'm thinking. I already have the code all setup with the image "echoed in" successfully, and I have two numerical values based on calculation on the form (which is done). My image looks like a graph, with an ongoing scale, in the shape of a diamond. (One scale running along the bottom to the left, and one from the bottom--to the right). Is there a way, based on the numerical result, for example, my two variables are $soc and $ec - could the script place them on the graph/image according to the scale? This might have been a bit confusing, so if you think this is possible, or if you need more input, just ask me. So any help would certainly be extremely appreciated. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/ Share on other sites More sharing options...
DeanWhitehouse Posted July 6, 2008 Share Posted July 6, 2008 i think you will need to have a look at using image gd. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583069 Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Hmm... well, in that case, I must ask if I need to install GD or if its already part of PHP 5. And you now probably know of my serious lack of experience in GD. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583075 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 It should be on your server. But what do you mean "plot" on an image? Show me an example. I can probably help you out. P.S: If it's a graph, I obviously know what you mean by plot, but I just want to make sure. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583079 Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Ok, thanks for the response. I attached an example of my "diamond". As you see there are two scales there on the bottom of the sides. I have two variables to match the scales in my script. Would I be able to take my first variable, $soc for the Social scale and $ec for the Economic scale and make one point where they meet on the image here? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583082 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Yeah, I don't think it would be too hard. It would be easier if it was just a square, but it's fine. I need to go eat, but I'll be back in a bit and I'll help. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583083 Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Yeah. Ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583086 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Okay. Now. What image do you want to use as a "point"? A single pixel wouldn't show up and be noticeable. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583100 Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Okay this is just a simple dot that I think would work. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583103 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Take a look at the function imagecopymerge. There are a lot of guides that show how to work with GD. You don't need anything big, so just look up how to load images and stuff. If you need any help with the code, feel free to ask. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583106 Share on other sites More sharing options...
vigiw Posted July 6, 2008 Author Share Posted July 6, 2008 Ok thanks. Would it be possible to do this if I simply echoed the image in, or do I need to do something special. Right now I have, just to call the image up for blank display: echo "<img src=\"diamond.bmp\">\n"; Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583110 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Yes, you need to do something special. You need make a new file. Name it diamonddraw.php. Then do: <img src="diamonddraw.php?soc=$soc&eco=$eco"> Then in diamonddraw.php, take those two variables from GET and use it to create the image and send the appropriate headers. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583113 Share on other sites More sharing options...
vigiw Posted July 7, 2008 Author Share Posted July 7, 2008 Thanks for the help, but I couldn't go about doing the GD thing. So I made my own image files. It took a while (121 of them), but they are done. Is there a way, though, to take one of my numerical variables in the PHP script and say, for example (since there are two variables on this graph) if $soc = 40 and $ec = 60 - show image diamond_s40e60.jpg I realize that wasn't in a PHP script format, but that's because I'm not sure how I would include that with both. Also, my numerical values will not be exactly, let's use the example--40 soc---it might be: soc = 37, ec = 55. Any ideas how to script that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583208 Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 printf('<img src="diamond_s%de%d" />', $soc, $ec); Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583214 Share on other sites More sharing options...
vigiw Posted July 7, 2008 Author Share Posted July 7, 2008 Thanks, but how would I tackle the rounding problem. Like if the user gets 86 for one of them or 43 for the other, i only have files for the Tens (e.g. 90 and 40) Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583215 Share on other sites More sharing options...
vigiw Posted July 7, 2008 Author Share Posted July 7, 2008 Any ideas on how to make that work? ??? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583534 Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 Sure, sorry. I didn't check for new posts. printf('<img src="diamond_s%de%d" />', round($soc, -1), round($ec, -1)); Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583539 Share on other sites More sharing options...
vigiw Posted July 7, 2008 Author Share Posted July 7, 2008 Thanks! I think its getting closer... but when the result is, for example for image diamond_s20e90.jpg - it will go to diamond_s-20e90.jpg But all of the files are saved as diamond_s#e#.jpg like above--but no hyphens like in the second image name. Again, thank you for helping! Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583547 Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 I'm not sure what you mean. I just tried: <?php $soc = 94; $ec = 32; printf('<img src="diamond_s%de%d" />', round($soc, -1), round($ec, -1)); ?> And it outputted: <img src="diamond_s90e30" /> Can I see what you have? Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583548 Share on other sites More sharing options...
vigiw Posted July 7, 2008 Author Share Posted July 7, 2008 It's probably because I changed one part, my fault for not mentioning it, I forgot. My points are based on 20, so I have another variable for $soc and $ec to multiply by 5 to get the percentage to plot on the map. That variable is just $soc_per and $ec_per printf('<img src="diamond_s%de%d.jpg" />', round($soc_per, -1), round($ec_per, -1)); But I think that's where it went wrong with the hyphens added in. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583551 Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 What's in $soc_per and $ec_per? Echo out: echo round($soc_per, -1) . " " . round($ec_per, -1); And make sure it's what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583554 Share on other sites More sharing options...
vigiw Posted July 7, 2008 Author Share Posted July 7, 2008 Ok thank you! I think it's all set now. In my if/else, when its <= 0, I made it = 0, it was going into the negatives, when I thought it was a hyphen. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/113474-php-script-to-plot-on-an-image/#findComment-583557 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.