[php] html kleur code in plaatje

Pagina: 1
Acties:

  • Engineer
  • Registratie: Juni 2001
  • Laatst online: 04-05 00:03
Hoi,
weet iemand hoe ik met php uit bijv #0418B0 de rgb kan halen? :)

thnx

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 21-09 13:51

Janoz

Moderator Devschuur®

!litemod

R = 04
G = 18
B = B0

Daar heb je je 3 bytes die de kleur aan geven (Owh ja, ze zijn wel hexadecimaal)

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


Verwijderd

Op maandag 17 september 2001 19:20 schreef hdd het volgende:
Hoi,
weet iemand hoe ik met php uit bijv #0418B0 de rgb kan halen? :)

thnx
04 = rr
18 = gg
B0 = bb
alle 3 hexadecimaal, dus per paar omrekenen naar decimaal

maar dat is vast niet wat je bedoelde?

  • chuxiej
  • Registratie: Februari 2001
  • Laatst online: 13-07-2020
Op maandag 17 september 2001 19:20 schreef hdd het volgende:
Hoi,
weet iemand hoe ik met php uit bijv #0418B0 de rgb kan halen? :)

thnx
PHP:
1
2
3
4
5
6
<?
$kleur = "#0418B0";
$r = substr($kleur,1,2);
$g = substr($kleur,3,2);
$b = substr($kleur,5,2);
?>

Geloof zoiets?

www.dannyhiemstra.nl


  • Engineer
  • Registratie: Juni 2001
  • Laatst online: 04-05 00:03
Op maandag 17 september 2001 19:28 schreef FireFoxx het volgende:

[..]
PHP:
1
2
3
4
5
6
<?
$kleur = "#0418B0";
$r = substr($kleur,1,2);
$g = substr($kleur,3,2);
$b = substr($kleur,5,2);
?>

Geloof zoiets?
Dat had ik al geprobeert:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
<?
$r = substr("$color",1,2);
$g = substr("$color",3,2);
$b = substr("$color",5,2);

$png = imagecreate(60,60);
$bg = ImageColorAllocate($png,$r,$g,$b);
ImageFilledRectangle($png,0,0,60,60,$bg);

header("content-type: image/Png"); 
imagepng($png);
?>

Maar als ik hem dan aanroep met color.php?color=#0418B0
Dan krijg ik zwart:Afbeeldingslocatie: http://212.83.93.125/onzin/color/color.php?color=#0418B0 terwijl het felgroen hoort te zijn :? :)

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 21-09 13:51

Janoz

Moderator Devschuur®

!litemod

Op maandag 17 september 2001 19:39 schreef hdd het volgende:

[..]

Dat had ik al geprobeert:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
<?
$r = substr("$color",1,2);
$g = substr("$color",3,2);
$b = substr("$color",5,2);

$png = imagecreate(60,60);
$bg = ImageColorAllocate($png,$r,$g,$b);
ImageFilledRectangle($png,0,0,60,60,$bg);

header("content-type: image/Png"); 
imagepng($png);
?>

Maar als ik hem dan aanroep met color.php?color=#0418B0
Dan krijg ik zwart:[afbeelding] terwijl het felgroen hoort te zijn :? :)
Je zult eerst de hexadecimale waarden in de strings $r,$b en $g om moeten zetten naar integers. Dat het plaatje nu zwart is, komt omdat php de waarden als strings ziet (want het is output van substring!!). Als je strings probeert te gebruiken als integer, dan komt er 0 uit. Dit verklaart ook het zwarte plaatje. Er is volgens mij wel een functie in php die een string omzet in een int. Daar kun je volgens mij ook een 'grondtal' invoeren, en aangezien het hexadecimale waarden zijn moet dit 16 zijn.

Dit is weer een nadeel van lose typing :)

[edit]

Net ff in php manual gekeken.. D'r is zelfs een speciale functie voor.. hexdec.. maw
PHP:
1
2
3
4
<?
$rs = substring(...);
$r=hexdec($rs);
?>

moet genoeg zijn :)

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • Engineer
  • Registratie: Juni 2001
  • Laatst online: 04-05 00:03
nope, kheb er nu dit van gemaakt:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?
$r = substr("$color",1,2);
$g = substr("$color",3,2);
$b = substr("$color",5,2);

$b = hexdec($b);
$g = hexdec($g);
$r = hexdec($r);

$png = imagecreate(60,60);
$bg = ImageColorAllocate($png,$r,$g,$b);
ImageFilledRectangle($png,0,0,60,60,$bg);

header("content-type: image/Png"); 
imagepng($png);
?>

En zoals je hierboven ziet is het plaatje nog steeds zwart ;(

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Heheheheh ... >:)

http://212.83.93.125/onzin/color/color.php?color=#0418B0 <---- Zie hekje?

Haal dat hekje eens weg en wat komt er dan? Je mooie vierkantje...

# is een anchor dus je $color is altijd leeg aangezien deze niet word doorgegeven... :)

Programmer - an organism that turns coffee into software.


  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 21-09 13:51

Janoz

Moderator Devschuur®

!litemod

Op maandag 17 september 2001 20:25 schreef LuCarD het volgende:
Heheheheh ... >:)

http://212.83.93.125/onzin/color/color.php?color=#0418B0 <---- Zie hekje?

Haal dat hekje eens weg en wat komt er dan? Je mooie vierkantje...

# is een anchor dus je $color is altijd leeg aangezien deze niet word doorgegeven... :)
idd.. # is een 'beschermt url teken', net als spatie, ?, & enz enz.. Je zult daarvoor in de plaats ff %23 moeten gebruiken (dat is de 'url escape code' van #)

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • Engineer
  • Registratie: Juni 2001
  • Laatst online: 04-05 00:03
Yep, nu doet ie het :) :) :)

Afbeeldingslocatie: http://212.83.93.125/onzin/color/color.php?color=%230418B0

  • frickY
  • Registratie: Juli 2001
  • Laatst online: 16-09 08:47
Ah crap, iemand was me voor. Dacht ik eindelijk ook eens iets intelligents te kunnen zeggen :S :+

Maar kan je ook iets anders dan vierkantjes tekenen? Een kwart rondje bijvoorbeeld? (voor gebruik linksboven in een tabel, zodat deze een ronde hoek krijgt)
Pagina: 1