cijfers-omzetten-in-7-segmenten

Gesponsorde koppelingen

PHP script bestanden

  1. cijfers-omzetten-in-7-segmenten

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php

  $value
= '75832';        // shown value max 9 characters
  
  // set the dimension of the character

  $a =6;                     // smaller then 3 gives a poor result. this value is the width of a segment in pixels
  
  // set the correction of the dimension of the image. 0 is default

  $width_corr  = '0';        // correction of the width of the image in pixels + or -
  $height_corr = '0';        // correction of the height of the image in pixels + or -
  
  // set the correction of the first (right) character. 0 is default

  $hor_corr  = 0;            // horizontal correction for the first (right) character in pixels + or -
  $vert_corr = 0;            // vertical correction for the first (right) character in pixels + or -

  if($value == '')
{

    $width = 100;
    $height = 30;
}

  elseif (strlen($value) > 9)
{

    $width = 110;
    $height = 50;
}

else
{
  $num_characters = strlen($value);

  $width = $a*7.5*$num_characters+$width_corr;        
  $height= $a*12+$height_corr;
}

  
  // make the image
  $image = ImageCreate($width,$height);
  
  // background color
  $bgcolor = ImageColorAllocate($image, 10, 10, 10);  

  // color of the character
  $color = imagecolorallocate($image, 0,255 ,0 );
  
  $hor_1 = $width-($a*6)+$hor_corr;
  $vert  = $height-($height*0.8)+$vert_corr;

  if($value == '')
{

    ImageString($image, 10, 15, 5, "no input", $color);
}

  elseif (strlen($value) > 9)
{

    ImageString($image, 5, 15, 5, "value out ", $color);
    ImageString($image, 5, 15, 20, "of range", $color);
}

  else
{

      if (strlen($value) == 1)                 // if there is one character
    {
        $value_1 = substr($value,0,1);  
    }

      if (strlen($value) == 2)                // if there are two characters
    {
        $value_1 = substr($value,1,1);
        $value_2 = substr($value,0,1);
    }

      if (strlen($value) == 3)                // if there are three characters
    {
        $value_1 = substr($value,2,1);
        $value_2 = substr($value,1,1);
        $value_3 = substr($value,0,1);
    }

      if (strlen($value) == 4)
    {

        $value_1 = substr($value,3,1);
        $value_2 = substr($value,2,1);
        $value_3 = substr($value,1,1);
        $value_4 = substr($value,0,1);
    }

          if (strlen($value) == 5)
    {

        $value_1 = substr($value,4,1);
        $value_2 = substr($value,3,1);
        $value_3 = substr($value,2,1);
        $value_4 = substr($value,1,1);
        $value_5 = substr($value,0,1);
    }

          if (strlen($value) == 6)
    {

        $value_1 = substr($value,5,1);
        $value_2 = substr($value,4,1);
        $value_3 = substr($value,3,1);
        $value_4 = substr($value,2,1);
        $value_5 = substr($value,1,1);
        $value_6 = substr($value,0,1);
    }

          if (strlen($value) == 7)
    {

        $value_1 = substr($value,6,1);
        $value_2 = substr($value,5,1);
        $value_3 = substr($value,4,1);
        $value_4 = substr($value,3,1);
        $value_5 = substr($value,2,1);
        $value_6 = substr($value,1,1);
        $value_7 = substr($value,0,1);
    }

          if (strlen($value) == 8)
    {

        $value_1 = substr($value,7,1);
        $value_2 = substr($value,6,1);
        $value_3 = substr($value,5,1);
        $value_4 = substr($value,4,1);
        $value_5 = substr($value,3,1);
        $value_6 = substr($value,2,1);
        $value_7 = substr($value,1,1);
        $value_8 = substr($value,0,1);
    }

          if (strlen($value) == 9)
    {

        $value_1 = substr($value,8,1);
        $value_2 = substr($value,7,1);
        $value_3 = substr($value,6,1);
        $value_4 = substr($value,5,1);
        $value_5 = substr($value,4,1);
        $value_6 = substr($value,3,1);
        $value_7 = substr($value,2,1);
        $value_8 = substr($value,1,1);
        $value_9 = substr($value,0,1);
    }


      $b = $a/2;
      $c = $a*2;
      $d = $a*3;
      $y = 2*$d;
      $z = 3*$a+3;
      
           for($i=0;$i<$num_characters;$i++)
        {
  
        
           $hor = $hor_1 -($i*7*$a+5);
      
            $segm_1 = array(
                  $a+2+$hor      , $vert,           // Point 1 (x, y)
                  $b+2+$hor      , $b+$vert,        // Point 2 (x, y)
                  $a+2+$hor      , $a+$vert,        // Point 3 (x, y)
                  $a+2+$c+$hor   , $a+$vert,        // Point 4 (x, y)
                  $a+2+$c+$b+$hor, $b+$vert,        // Point 5 (x, y)
                  $a+2+$c+$hor   , $vert,           // Point 6 (x, y)
                  );
            $segm_7 = array(
                  $a+2+$hor      , $d+$vert,        // Point 1 (x, y)
                  $b+2+$hor      , $b+$d+$vert,     // Point 2 (x, y)
                  $a+2+$hor      , $a+$d+$vert,     // Point 3 (x, y)
                  $a+2+$c+$hor   , $a+$d+$vert,     // Point 4 (x, y)
                  $a+2+$c+$b+$hor, $b+$d+$vert,     // Point 5 (x, y)
                  $a+2+$c+$hor   , $d+$vert,        // Point 6 (x, y)
                  );
            $segm_4 = array(
                  $a+2+$hor      , $y+$vert,        // Point 1 (x, y)
                  $b+2+$hor      , $b+$y+$vert,     // Point 2 (x, y)
                  $a+2+$hor      , $a+$y+$vert,     // Point 3 (x, y)
                  $a+2+$c+$hor   , $a+$y+$vert,     // Point 4 (x, y)
                  $a+2+$c+$b+$hor, $b+$y+$vert,     // Point 5 (x, y)
                  $a+2+$c+$hor   , $y+$vert,        // Point 6 (x, y)
                  );

            $segm_2 = array(
                  $b+$hor       , $b+1+$vert,       // Point 1 (x, y)
                  $hor          , $a+1+$vert,       // Point 2 (x, y)
                  $hor          , $d-1+$vert,       // Point 3 (x, y)
                  $b+$hor       , $b-1+$d+$vert,    // Point 4 (x, y)
                  $a+$hor       , $d-1+$vert,       // Point 5 (x, y)
                  $a+$hor       , $a+1+$vert,       // Point 6 (x, y)
                  );
            $segm_3 = array(
                  $b+$hor       , $b+1+$d+$vert,    // Point 1 (x, y)
                  $hor          , $a+1+$d+$vert,    // Point 2 (x, y)
                  $hor          , $d-1+$d+$vert,    // Point 3 (x, y)
                  $b+$hor       , $b-1+$d+$d+$vert, // Point 4 (x, y)
                  $a+$hor       , $d-1+$d+$vert,    // Point 5 (x, y)
                  $a+$hor       , $a+1+$d+$vert,    // Point 6 (x, y)
                  );
            $segm_5 = array(
                  $b+1+$z+$hor  , $b+1+$vert,       // Point 1 (x, y)
                  $z+1+$hor     , $a+1+$vert,       // Point 2 (x, y)
                  $z+1+$hor     , $d-1+$vert,       // Point 3 (x, y)
                  $b+1+$z+$hor  , $b-1+$d+$vert,    // Point 4 (x, y)
                  $a+1+$z+$hor  , $d-1+$vert,       // Point 5 (x, y)
                  $a+1+$z+$hor  , $a+1+$vert,       // Point 6 (x, y)
                  );
            $segm_6 = array(
                  $b+1+$z+$hor  , $b+1+$d+$vert,    // Point 1 (x, y)
                  $z+1+$hor     , $a+1+$d+$vert,    // Point 2 (x, y)
                  $z+1+$hor     , $d-1+$d+$vert,    // Point 3 (x, y)
                  $b+1+$z+$hor  , $b-1+$d+$d+$vert, // Point 4 (x, y)
                  $a+1+$z+$hor  , $d-1+$d+$vert,    // Point 5 (x, y)
                  $a+1+$z+$hor  , $a+1+$d+$vert,    // Point 6 (x, y)
                  );

        if($i == '0'){$char = $value_1;}
        if($i == '1'){$char = $value_2;}
        if($i == '2'){$char = $value_3;}
        if($i == '3'){$char = $value_4;}
        if($i == '4'){$char = $value_5;}
        if($i == '5'){$char = $value_6;}
        if($i == '6'){$char = $value_7;}
        if($i == '7'){$char = $value_8;}
        if($i == '8'){$char = $value_9;}


        if($char == '0'|$char == '2'|$char == '3'|$char == '5'|$char == '6'|$char == '7'|$char == '8'|$char == '9')               {imagefilledpolygon($image, $segm_1, 6, $color);}
        if($char == '0'|$char == '4'|$char == '5'|$char == '6'|$char == '8'|$char == '9')                                         {imagefilledpolygon($image, $segm_2, 6, $color);}
        if($char == '0'|$char == '2'|$char == '6'|$char == '8')                                                                   {imagefilledpolygon($image, $segm_3, 6, $color);}
        if($char == '0'|$char == '2'|$char == '3'|$char == '5'|$char == '6'|$char == '8')                                         {imagefilledpolygon($image, $segm_4, 6, $color);}
        if($char == '0'|$char == '1'|$char == '2'|$char == '3'|$char == '4'|$char == '7'|$char == '8'|$char == '9')               {imagefilledpolygon($image, $segm_5, 6, $color);}
        if($char == '0'|$char == '1'|$char == '3'|$char == '4'|$char == '5'|$char == '6'|$char == '7'|$char == '8'|$char == '9')  {imagefilledpolygon($image, $segm_6, 6, $color);}
        if($char == '2'|$char == '3'|$char == '4'|$char == '5'|$char == '6'|$char == '8'|$char == '9')                            {imagefilledpolygon($image, $segm_7, 6, $color);}
      
    }
}

header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>


En nu nog een script met een afbeelding als achtergrond


Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php

  $value
= '84';                // shown value max 2 characters
  
  if($value == ''){$empty ="yes"; } else {$empty = "no";}
  
  $length = strlen($value);       // numbers of caracters
  
  // set the dimension of the character

  $a =5;                          // smaller then 3 gives a poor result. this value is the width of a segment in pixels
  
  // set the correction of the first (right) character. 0 is default

  $hor_1  = 72;        
  $vert   = 37;
    
  // make the image
  $image = imagecreatefrompng("http://www.kiekkast.nl/Indicators/img_digi/gele_meter_2_klein.png");
  
  // background color
  $bgcolor = ImageColorAllocate($image, 10, 10, 10);  

  // color of the character
  $color = imagecolorallocate($image, 50,50 ,50 );
  
  if($empty == 'yes')
{

    ImageString($image, 4, 34, 40, "no input", $color);
}

  elseif ($length > 2)
{

    ImageString($image, 4, 34, 35, "value out ", $color);
    ImageString($image, 4, 34, 50, "of range", $color);
}

  else
{
    $b = $a/2;
    $c = $a*2;
    $d = $a*3;
    $y = 2*$d;
    $z = 3*$a+3;
      
      for($i=0;$i<$length;$i++)
    {
  

        $hor = $hor_1 -($i*6*$a);

        $segm_1 = array(
                  $a+2+$hor      , $vert,           // Point 1 (x, y)
                  $b+2+$hor      , $b+$vert,        // Point 2 (x, y)
                  $a+2+$hor      , $a+$vert,        // Point 3 (x, y)
                  $a+2+$c+$hor   , $a+$vert,        // Point 4 (x, y)
                  $a+2+$c+$b+$hor, $b+$vert,        // Point 5 (x, y)
                  $a+2+$c+$hor   , $vert,           // Point 6 (x, y)
                  );
        $segm_7 = array(
                  $a+2+$hor      , $d+$vert,        // Point 1 (x, y)
                  $b+2+$hor      , $b+$d+$vert,     // Point 2 (x, y)
                  $a+2+$hor      , $a+$d+$vert,     // Point 3 (x, y)
                  $a+2+$c+$hor   , $a+$d+$vert,     // Point 4 (x, y)
                  $a+2+$c+$b+$hor, $b+$d+$vert,     // Point 5 (x, y)
                  $a+2+$c+$hor   , $d+$vert,        // Point 6 (x, y)
                  );
        $segm_4 = array(
                  $a+2+$hor      , $y+$vert,        // Point 1 (x, y)
                  $b+2+$hor      , $b+$y+$vert,     // Point 2 (x, y)
                  $a+2+$hor      , $a+$y+$vert,     // Point 3 (x, y)
                  $a+2+$c+$hor   , $a+$y+$vert,     // Point 4 (x, y)
                  $a+2+$c+$b+$hor, $b+$y+$vert,     // Point 5 (x, y)
                  $a+2+$c+$hor   , $y+$vert,        // Point 6 (x, y)
                  );

        $segm_2 = array(
                  $b+$hor       , $b+1+$vert,       // Point 1 (x, y)
                  $hor          , $a+1+$vert,       // Point 2 (x, y)
                  $hor          , $d-1+$vert,       // Point 3 (x, y)
                  $b+$hor       , $b-1+$d+$vert,    // Point 4 (x, y)
                  $a+$hor       , $d-1+$vert,       // Point 5 (x, y)
                  $a+$hor       , $a+1+$vert,       // Point 6 (x, y)
                  );
        $segm_3 = array(
                  $b+$hor       , $b+1+$d+$vert,    // Point 1 (x, y)
                  $hor          , $a+1+$d+$vert,    // Point 2 (x, y)
                  $hor          , $d-1+$d+$vert,    // Point 3 (x, y)
                  $b+$hor       , $b-1+$d+$d+$vert, // Point 4 (x, y)
                  $a+$hor       , $d-1+$d+$vert,    // Point 5 (x, y)
                  $a+$hor       , $a+1+$d+$vert,    // Point 6 (x, y)
                  );
        $segm_5 = array(
                  $b+1+$z+$hor  , $b+1+$vert,       // Point 1 (x, y)
                  $z+1+$hor     , $a+1+$vert,       // Point 2 (x, y)
                  $z+1+$hor     , $d-1+$vert,       // Point 3 (x, y)
                  $b+1+$z+$hor  , $b-1+$d+$vert,    // Point 4 (x, y)
                  $a+1+$z+$hor  , $d-1+$vert,       // Point 5 (x, y)
                  $a+1+$z+$hor  , $a+1+$vert,       // Point 6 (x, y)
                  );
        $segm_6 = array(
                  $b+1+$z+$hor  , $b+1+$d+$vert,    // Point 1 (x, y)
                  $z+1+$hor     , $a+1+$d+$vert,    // Point 2 (x, y)
                  $z+1+$hor     , $d-1+$d+$vert,    // Point 3 (x, y)
                  $b+1+$z+$hor  , $b-1+$d+$d+$vert, // Point 4 (x, y)
                  $a+1+$z+$hor  , $d-1+$d+$vert,    // Point 5 (x, y)
                  $a+1+$z+$hor  , $a+1+$d+$vert,    // Point 6 (x, y)
                  );
        $char = substr($value, $length-1-$i ,1);
        
        if($char == '0'|$char == '2'|$char == '3'|$char == '5'|$char == '6'|$char == '7'|$char == '8'|$char == '9')               {imagefilledpolygon($image, $segm_1, 6, $color);}
        if($char == '0'|$char == '4'|$char == '5'|$char == '6'|$char == '8'|$char == '9')                                         {imagefilledpolygon($image, $segm_2, 6, $color);}
        if($char == '0'|$char == '2'|$char == '6'|$char == '8')                                                                   {imagefilledpolygon($image, $segm_3, 6, $color);}
        if($char == '0'|$char == '2'|$char == '3'|$char == '5'|$char == '6'|$char == '8')                                         {imagefilledpolygon($image, $segm_4, 6, $color);}
        if($char == '0'|$char == '1'|$char == '2'|$char == '3'|$char == '4'|$char == '7'|$char == '8'|$char == '9')               {imagefilledpolygon($image, $segm_5, 6, $color);}
        if($char == '0'|$char == '1'|$char == '3'|$char == '4'|$char == '5'|$char == '6'|$char == '7'|$char == '8'|$char == '9')  {imagefilledpolygon($image, $segm_6, 6, $color);}
        if($char == '2'|$char == '3'|$char == '4'|$char == '5'|$char == '6'|$char == '8'|$char == '9')                            {imagefilledpolygon($image, $segm_7, 6, $color);}
    }
}


  header('Content-type: image/png');
  imagepng($image);
  imagedestroy($image);
?>


René

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.