3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ColorLuminance($hex, $lum) { // validate hex string $hex = preg_replace("/[^0-9a-f]/i", "", $hex); if (strlen($hex) < 6) { $hex = $hex[0] + $hex[0] + $hex[1] + $hex[1] + $hex[2] + $hex[2]; } // convert to decimal and change luminosity $rgb = "#"; for ($i = 0; $i < 3; $i++) { $c = base_convert(substr($hex, $i * 2, 2), 16, 10); $c = base_convert((round(min(max(0, floatval($c . ($c * $lum))),255))), 10, 16); $rgb .= substr('00' . $c, strlen($c)); } return $rgb; } echo ColorLuminance("#69c", 0) . "\n"; // returns "#6699cc" echo ColorLuminance("6699CC", 0.2) . "\n";// "#7ab8f5" - 20% lighter echo ColorLuminance("69C", -0.5) . "\n";// "#334d66" - 50% darker echo ColorLuminance("000", 1) . "\n";// "#000000" - true black cannot be made lighter!
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ETdsb
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'colorluminance'
          1        SEND_VAL                                                 '%2369c'
          2        SEND_VAL                                                 0
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      $0, '%0A'
          5        ECHO                                                     ~1
   23     6        INIT_FCALL                                               'colorluminance'
          7        SEND_VAL                                                 '6699CC'
          8        SEND_VAL                                                 0.2
          9        DO_FCALL                                      0  $2      
         10        CONCAT                                           ~3      $2, '%0A'
         11        ECHO                                                     ~3
   24    12        INIT_FCALL                                               'colorluminance'
         13        SEND_VAL                                                 '69C'
         14        SEND_VAL                                                 -0.5
         15        DO_FCALL                                      0  $4      
         16        CONCAT                                           ~5      $4, '%0A'
         17        ECHO                                                     ~5
   25    18        INIT_FCALL                                               'colorluminance'
         19        SEND_VAL                                                 '000'
         20        SEND_VAL                                                 1
         21        DO_FCALL                                      0  $6      
         22        CONCAT                                           ~7      $6, '%0A'
         23        ECHO                                                     ~7
         24      > RETURN                                                   1

Function colorluminance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 26
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 26
Branch analysis from position: 68
Branch analysis from position: 26
Branch analysis from position: 23
filename:       /in/ETdsb
function name:  ColorLuminance
number of ops:  70
compiled vars:  !0 = $hex, !1 = $lum, !2 = $rgb, !3 = $i, !4 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%2F%5B%5E0-9a-f%5D%2Fi'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !0, $5
    7     8        STRLEN                                           ~7      !0
          9        IS_SMALLER                                               ~7, 6
         10      > JMPZ                                                     ~8, ->23
    8    11    >   FETCH_DIM_R                                      ~9      !0, 0
         12        FETCH_DIM_R                                      ~10     !0, 0
         13        ADD                                              ~11     ~9, ~10
         14        FETCH_DIM_R                                      ~12     !0, 1
         15        ADD                                              ~13     ~11, ~12
         16        FETCH_DIM_R                                      ~14     !0, 1
         17        ADD                                              ~15     ~13, ~14
         18        FETCH_DIM_R                                      ~16     !0, 2
         19        ADD                                              ~17     ~15, ~16
         20        FETCH_DIM_R                                      ~18     !0, 2
         21        ADD                                              ~19     ~17, ~18
         22        ASSIGN                                                   !0, ~19
   12    23    >   ASSIGN                                                   !2, '%23'
   13    24        ASSIGN                                                   !3, 0
         25      > JMP                                                      ->66
   14    26    >   INIT_FCALL                                               'base_convert'
         27        INIT_FCALL                                               'substr'
         28        SEND_VAR                                                 !0
         29        MUL                                              ~23     !3, 2
         30        SEND_VAL                                                 ~23
         31        SEND_VAL                                                 2
         32        DO_ICALL                                         $24     
         33        SEND_VAR                                                 $24
         34        SEND_VAL                                                 16
         35        SEND_VAL                                                 10
         36        DO_ICALL                                         $25     
         37        ASSIGN                                                   !4, $25
   15    38        INIT_FCALL                                               'base_convert'
         39        INIT_FCALL                                               'round'
         40        INIT_FCALL                                               'min'
         41        INIT_FCALL                                               'max'
         42        SEND_VAL                                                 0
         43        MUL                                              ~27     !4, !1
         44        CONCAT                                           ~28     !4, ~27
         45        CAST                                          5  ~29     ~28
         46        SEND_VAL                                                 ~29
         47        DO_ICALL                                         $30     
         48        SEND_VAR                                                 $30
         49        SEND_VAL                                                 255
         50        DO_ICALL                                         $31     
         51        SEND_VAR                                                 $31
         52        DO_ICALL                                         $32     
         53        SEND_VAR                                                 $32
         54        SEND_VAL                                                 10
         55        SEND_VAL                                                 16
         56        DO_ICALL                                         $33     
         57        ASSIGN                                                   !4, $33
   16    58        INIT_FCALL                                               'substr'
         59        CONCAT                                           ~35     '00', !4
         60        SEND_VAL                                                 ~35
         61        STRLEN                                           ~36     !4
         62        SEND_VAL                                                 ~36
         63        DO_ICALL                                         $37     
         64        ASSIGN_OP                                     8          !2, $37
   13    65        PRE_INC                                                  !3
         66    >   IS_SMALLER                                               !3, 3
         67      > JMPNZ                                                    ~40, ->26
   19    68    > > RETURN                                                   !2
   20    69*     > RETURN                                                   null

End of function colorluminance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.41 ms | 1406 KiB | 29 Q