thechris Posted November 18, 2006 Share Posted November 18, 2006 Ok I'm not sure if this is possible or not but I thought I would ask.When looking at a characters stats I want to have thier data displayed like this[IMG]http://img.photobucket.com/albums/v63/vokus/0000534.jpg[/img]but I don't want to make images for all the combos and was wondering if I could do it based off of thier stats from the database and how would I do it? Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/ Share on other sites More sharing options...
zq29 Posted November 18, 2006 Share Posted November 18, 2006 Heres a method of doing it, although I have only made it plot the health, stamina and dexterity points, it should be quite simple to work out how to make it plot the other four points.The only issue with this method is that the pink line is only 1px thick, I'm not sure of an easy method to make it thicker other than to create the polygon several times with a slight offset...Hope this helps...[code]<?phpfunction buildimage($h,$s,$d) { $health = array("128,122","119,99","111,77","104,58","97,38","90,22"); $stamina = array("128,122","140,102","152,81","163,62","175,48","182,33"); $dexterity = array("128,122","149,120","167,118","190,116","209,113","230,103"); $coords = explode(",",$health[$h].",".$stamina[$s].",".$dexterity[$d]); $im = imagecreatefromjpeg("base.jpg"); $col_poly = imagecolorallocate($im,201,0,201); imagepolygon($im,$coords,count($coords)/2,$col_poly); header("Content-type: image/png"); imagepng($im);}buildimage(0,1,2);?>[/code][b]EDIT:[/b] Turns out you can set the thickness of the line with the imagesetthickness() function! Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/#findComment-126648 Share on other sites More sharing options...
spelltwister Posted November 18, 2006 Share Posted November 18, 2006 You can do this from a simple formula for an n-sided polygon. I'm not sure exactly sure what determines what, but it seems that Str, Combo, Stam, and Dex are the determining stats for the other 4, IE, the combo of those results int the other? maybe not.If not, you can just do something like take the first stat (lets say STR), and see what it's value is. Lets say 2, so the line polygon starts at 2*(space between each value) in the -y direction (assuming the center as the origin). Take the next stat, lets say SPECIAL. Check how far that goes out. Now, let's say 4. It's end point is 4cos(roughly 240) in the x, and 4sin(roughly 240) in the y. That's two verticies. Just continue around until you get all the verticies and have the first one as the last one too. You'll have to know the angle that each point out from , or transform the verticies at the end. Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/#findComment-126721 Share on other sites More sharing options...
thechris Posted November 19, 2006 Author Share Posted November 19, 2006 [quote author=SemiApocalyptic link=topic=115439.msg470085#msg470085 date=1163868439]Heres a method of doing it, although I have only made it plot the health, stamina and dexterity points, it should be quite simple to work out how to make it plot the other four points.The only issue with this method is that the pink line is only 1px thick, I'm not sure of an easy method to make it thicker other than to create the polygon several times with a slight offset...Hope this helps...[code]<?phpfunction buildimage($h,$s,$d) { $health = array("128,122","119,99","111,77","104,58","97,38","90,22"); $stamina = array("128,122","140,102","152,81","163,62","175,48","182,33"); $dexterity = array("128,122","149,120","167,118","190,116","209,113","230,103"); $coords = explode(",",$health[$h].",".$stamina[$s].",".$dexterity[$d]); $im = imagecreatefromjpeg("base.jpg"); $col_poly = imagecolorallocate($im,201,0,201); imagepolygon($im,$coords,count($coords)/2,$col_poly); header("Content-type: image/png"); imagepng($im);}buildimage(0,1,2);?>[/code][b]EDIT:[/b] Turns out you can set the thickness of the line with the imagesetthickness() function![/quote]It tells me when I test it in a browserThe image “http://localhost/cosplaycombat/test.php” cannot be displayed, because it contains errors.I changed the code to load the blank image because I don't have it named as you didWhat version of PHP do I need to have to correctly use this because I have php 5.2.0 Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/#findComment-126833 Share on other sites More sharing options...
Barand Posted November 19, 2006 Share Posted November 19, 2006 I never could resist a challenge, especially when it can be useful addition to my libraryTwo files, first on to test the chart and second produces the chart::test_webchart.php::[code]<html><head><meta name="author" content="Barand"><meta name="generator" content="PhpED 4.5"><meta name="creation-date" content="11/19/2006"><title>WebChart Test</title></head><body> <?php $data = array ( 'Dexterity' => 20, 'Stamina' => 40, 'Health' => 50, 'Combo' => 100, 'Special' => 20, 'Strength' => 60, 'Dodge' => 70 ); $items = join(',', array_keys($data)); $scores = join(',', array_values($data)); echo "<img src='webchart.php?items=$items&scores=$scores'>" ?> </body></html>[/code]::webchart.php::[code]<?phpclass webChart { /********************************* ** WebChart class ** Author : B Andrew (Barand) ** Date : 19 Nov 2006 *********************************/ var $items; var $scores; var $firstAngle = 10; var $angles; var $numpts; var $radius1; var $radius2; var $font; var $fontsize; var $size; var $im; var $bg; var $plotcolor; var $webcolor; function webChart($size,$items, $scores, $angle1, $rad1, $rad2, $font, $fontsize, $bgcolor, $webcolor, $plotcolor) { /*************************************************** * args: * image size * comma delimited list of item labels * comma delimited list of scores (values 0 to 100) * angle in degrees of first web radial * radius of main radials * radius of max value on radials * path to label font file * sixe of label font * image background color * color foe web and labels * color for plotting score values *******************************************************/ $this->size = $size; $this->angles = array(); $this->items = explode(',', $items); $this->scores = explode(',', $scores); $this->font = $font; $this->fontsize = $fontsize; $this->numpts = count($this->items); $this->im = imagecreatetruecolor($size, $size); $this->bg = imagecolorallocate($this->im, ($bgcolor>>16)& 0xFF, ($bgcolor>>8)& 0xFF,$bgcolor & 0xFF); $this->webcolor = imagecolorallocate($this->im, ($webcolor>>16)& 0xFF, ($webcolor>>8)& 0xFF,$webcolor & 0xFF); $this->plotcolor = imagecolorallocatealpha($this->im, ($plotcolor>>16)& 0xFF, ($plotcolor>>8)& 0xFF,$plotcolor & 0xFF, 65); $this->radius1 = $rad1; $this->radius2 = $rad2; $this->firstAngle = $angle1; } function display() { imagefill($this->im, 0,0, $this->bg); $this->drawWeb(); $this->drawLabels(); $this->plotData(); header("content-type: image/png"); imagepng($this->im); imagedestroy($this->im); } function drawWeb() { $ang = 360/$this->numpts; $cx = $cy = $this->size/2; imagesetthickness($this->im, 3); for ($i=$this->firstAngle; $i <= 360; $i+=$ang) { $a = -deg2rad($i); $this->angles[] = $a; imageline($this->im, $cx, $cy, $cx+$this->radius1*cos($a), $cy+$this->radius1*sin($a), $this->webcolor); } $this->angles[] = -deg2rad($this->firstAngle); $rstep = $this->radius2/5; for ($r=$rstep; $r<=$this->radius2; $r+=$rstep) { for ($i=0; $i<$this->numpts; $i++) { imageline($this->im,$cx+$r*cos($this->angles[$i]), $cy+$r*sin($this->angles[$i]), $cx+$r*cos($this->angles[$i+1]), $cy+$r*sin($this->angles[$i+1]), $this->webcolor); } } } function plotData() { $pts = array(); $k=0; $cx = $cy = $this->size/2; foreach ($this->scores as $s) { $pts[] = $cx+($s*$this->radius2/100)*cos($this->angles[$k]); $pts[] = $cy+($s*$this->radius2/100)*sin($this->angles[$k]); $k++; } imagefilledpolygon($this->im,$pts,$k,$this->plotcolor); } function drawLabels() { $k=0; $cx = $cy = $this->size/2; foreach ($this->items as $txt) { $r = $this->angles[$k] < -M_PI ? $this->radius1+20 : $this->radius1+10; // calculate angular offset to centre text on radial $tb = imagettfbbox($this->fontsize, 0, $this->font, $txt); $tw = $tb[2]-$tb[0]; $ta = asin($tw/(2*$r)); $offset = $this->angles[$k] < -M_PI ? $ta : -$ta; $x = $cx + $r*cos($this->angles[$k] + $offset); $y = $cy + $r*sin($this->angles[$k] + $offset); $ang = $this->angles[$k] < -M_PI ? rad2deg(M_PI/2 - $this->angles[$k] ) : rad2deg(M_PI*3/2 - $this->angles[$k] ) ; imagettftext($this->im,$this->fontsize,$ang, $x, $y, $this->webcolor, $this->font, $txt); $k++; } }} # class webChart$items = $_GET['items'];$scores = $_GET['scores'];$obj = new webChart(230,$items, $scores, 10, 80, 70, 'c:/windows/fonts/arial.ttf', 12, 0x0000FF, 0, 0xFF00FF);$obj->display();?>[/code] Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/#findComment-127022 Share on other sites More sharing options...
zq29 Posted November 20, 2006 Share Posted November 20, 2006 [quote author=thechris link=topic=115439.msg470279#msg470279 date=1163896639]It tells me when I test it in a browserThe image “http://localhost/cosplaycombat/test.php” cannot be displayed, because it contains errors.I changed the code to load the blank image because I don't have it named as you didWhat version of PHP do I need to have to correctly use this because I have php 5.2.0[/quote]I'm running 4.4.2 and it's working perfectly, although I don't see any reason as to why it should fail with 5.2.0Can you display your base image ok? - I.e. are you sure there are no problems with your base image? Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/#findComment-127579 Share on other sites More sharing options...
Barand Posted November 20, 2006 Share Posted November 20, 2006 SA - I can confirm it works OK with v5.1.2 Link to comment https://forums.phpfreaks.com/topic/27678-dynamic-image/#findComment-127661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.