Beamer Posted March 21, 2006 Share Posted March 21, 2006 I'm pretty new to GD, but I want to make an image that grabs a hex color code from a 'color' string and puts it in the background of an transparent image. For example, I have a transparent circle with a black border. I decide I like it to be blue so I do circle.php?color=0000ff which results in me having a blue circle with a black border. I have tried doing a script with references from PHP.net but I can't get it to work.Does anyone here have a script or can create one to what I would like it to do?Cheers,- B. Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/ Share on other sites More sharing options...
redbullmarky Posted March 21, 2006 Share Posted March 21, 2006 modified from an example on php.net/imagefilledellipse. you'll need to change it again to suit your needs:[code]// break up color into its RGB parts$color = $_GET['color'];$r = hexdec(substr($color,0,2));$g = hexdec(substr($color,2,2));$b = hexdec(substr($color,4,2));// fill the background color white$bg = imagecolorallocate($image, 255, 255, 255);// choose a color for the ellipse$col_ellipse = imagecolorallocate($image, $r, $g, $b);// draw the ellipseimagefilledellipse($image, 200, 150, 300, 200, $col_ellipse);[/code]hope that helps. i've not tested it but should work or set you on your way...CheersMark Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19312 Share on other sites More sharing options...
Beamer Posted March 21, 2006 Author Share Posted March 21, 2006 My problem is that the top isn't an image, it's a rectangle button with a bit of transparent pixels which users can choose a color for.I believe your script is using the ellipse function which was in my example, sorry about that.[b]EDIT: [/b]I get two errors when trying out: color=ff0000Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 9Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 12 Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19469 Share on other sites More sharing options...
redbullmarky Posted March 21, 2006 Share Posted March 21, 2006 [!--quoteo(post=357100:date=Mar 21 2006, 09:23 PM:name=Beamer)--][div class=\'quotetop\']QUOTE(Beamer @ Mar 21 2006, 09:23 PM) [snapback]357100[/snapback][/div][div class=\'quotemain\'][!--quotec--][b]EDIT: [/b]I get two errors when trying out: color=ff0000Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 9Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 12[/quote]did you create the image first? sorry, i didnt include that in my example as i thought you'd already have that bit, but you need to use:[code]$width = 800; $height = 600;$image = imagecreate($width, $height);[/code]before you use imagecolorallocate, etc. (you can also use 'imagecreatetruecolor' in the same way).the script will work with any sort of GD drawing, whether it be an ellipse, rectangle, polygon, line, etc. have a look at the manual (http://php.net/imagecreate) for details on getting things set up and also links to all the other functions you may find useful. Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19495 Share on other sites More sharing options...
Beamer Posted March 21, 2006 Author Share Posted March 21, 2006 Sorry, but I mean the top layer is an external image from the server and I want to put that over a colored background. Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19498 Share on other sites More sharing options...
redbullmarky Posted March 22, 2006 Share Posted March 22, 2006 [!--quoteo(post=357130:date=Mar 21 2006, 10:54 PM:name=Beamer)--][div class=\'quotetop\']QUOTE(Beamer @ Mar 21 2006, 10:54 PM) [snapback]357130[/snapback][/div][div class=\'quotemain\'][!--quotec--]Sorry, but I mean the top layer is an external image from the server and I want to put that over a colored background.[/quote]the priciples and practices are exactly the same whatever you want to do, if it is in fact the GD you want/need.[code]$color = $_GET['color'];$r = hexdec(substr($color,0,2));$g = hexdec(substr($color,2,2));$b = hexdec(substr($color,4,2));[/code]if it's an element you need to change, depending on the $_GET value of 'color', then just insert it where you would normally do it with CSS. for example:[code]<div style="background-color:#<?php echo $_GET['color']; ?>"><p>hello world!<p></div>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19608 Share on other sites More sharing options...
Beamer Posted March 23, 2006 Author Share Posted March 23, 2006 I knew that thanks, but I'm having trouble making the image be put over the background using GD. Quote Link to comment https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19817 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.