Jump to content

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/5412-gd-problems/
Share on other sites

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 ellipse
imagefilledellipse($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...

Cheers
Mark

Link to comment
https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19312
Share on other sites

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=ff0000

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 9

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 12
Link to comment
https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19469
Share on other sites

[!--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=ff0000

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in test.php on line 9

Warning: 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.
Link to comment
https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19495
Share on other sites

[!--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]
Link to comment
https://forums.phpfreaks.com/topic/5412-gd-problems/#findComment-19608
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.