Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-08-2009, 05:53 PM   PM User | #1
Pandabeer
New Coder

 
Join Date: Mar 2009
Posts: 43
Thanks: 2
Thanked 0 Times in 0 Posts
Pandabeer has a little shameless behaviour in the past
converting coordinates

im not pro @ maths, but this is what i want, i have some coordinates from a game (account info) and those are going from -9999.9999 till 9999.9999 so how to convert them to something that'll fit in a picture of 1536x1536 pixels (with imagecopy because ill put an icon over it)
Pandabeer is offline   Reply With Quote
Old 05-08-2009, 06:05 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
So the exact center is 0,0 ?
And the upper-left corner is -9999, 9999?
mlseim is offline   Reply With Quote
Old 05-08-2009, 06:07 PM   PM User | #3
Pandabeer
New Coder

 
Join Date: Mar 2009
Posts: 43
Thanks: 2
Thanked 0 Times in 0 Posts
Pandabeer has a little shameless behaviour in the past
Quote:
Originally Posted by mlseim View Post
So the exact center is 0,0 ?
And the upper-left corner is -9999, 9999?
center = 0,0 down-left corner = -9999,9999 ( dunno exact ) and upper right corner = 9999,9999 ( same )
Pandabeer is offline   Reply With Quote
Old 05-08-2009, 08:11 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
See image attached ...

So, if I'm correct, you're placing your image (in red) onto the graph (in black).

Let us know if that is the correct idea of what you're doing.

EDIT:
Here's what I came up with ...
PHP Code:
<?php 
// Highlight point of an image based on coordinates.

// Make-up some Coordinates (for testing purposes)
$x=-5000;
$y=5000;

// Generate Image & determine width X Height 
$image imagecreatefromjpeg("yourpicture.jpg"); 
$imageWidth imagesx($image); 
$imageHeight imagesy($image);

// Determine the center of the image.
$imageCenterWidth $imageWidth/2;
$imageCenterHeight $imageHeight/2;

// Your coordinate system is -9999 to 9999,
$divx $imageCenterWidth/9999;
$divy $imageCenterHeight/9999;

$px $imageCenterWidth abs(round($x $divx));
if(
$x<0){
$px $imageCenterWidth abs(round($x $divx));
}

$py $imageCenterHeight abs(round($y $divy));
if(
$y>0){
$py $imageCenterHeight abs(round($y $divy));
}

// Do your pixel or ttf (text) thing here.
// Set the text or pixels at $px,$py

// Output & Free Memory 
header("Content-type: image/jpeg"); 
imagejpeg($image); 
imagedestroy($image); 

?>
Attached Thumbnails
Click image for larger version

Name:	graph.gif
Views:	38
Size:	6.5 KB
ID:	7376  

Last edited by mlseim; 05-09-2009 at 03:22 AM..
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:00 AM.


Advertisement
Log in to turn off these ads.