Jump to content

PHP Script to Plot on an Image


vigiw

Recommended Posts

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! ;D).  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! :)

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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.