Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > PDF > FPDF
FPDF Forum d'entraide pour la bibliothèque FPDF permettant de générer des documents PDF en PHP. Avant de poster -> tutoriels FPDF
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 13/05/2008, 13h04   #1
Invité de passage
 
Inscription : mai 2008
Messages : 5
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 5
Points : 1
Points : 1
Par défaut [FPDF] FPDF et générateur de code-barres

Hello,

Travaillant actuellement sur l'affichage de code-barres dans FPDF, je dois me baser sur la classe pi_barcode.

Problème: la classe ne fonctionne que sous la forme suivante:

<img style="display:block;" width="280" height="95" src=includes/pi_barcode.php?type=C128C&code32342343">

Et FPDF ne peut lire que les images "en dur" (.png, .jpg).

J'aimerais donc adapter la classe pour qu'elle me copie une image plutôt qu'elle me la génère de façon dynamique.

Voici le code de la classe pi_barcode.php :

Code :
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
class pi_barcode
{
    /**
    * Définition des symbologies
    */
	
	var $C128 = array(
				0 => "11011001100",     1 => "11001101100",     2 => "11001100110",
				3 => "10010011000",     4 => "10010001100",     5 => "10001001100",
				6 => "10011001000",     7 => "10011000100",     8 => "10001100100",
				9 => "11001001000",     10 => "11001000100",    11 => "11000100100",
				12 => "10110011100",    13 => "10011011100",    14 => "10011001110",
				15 => "10111001100",    16 => "10011101100",    17 => "10011100110",
				18 => "11001110010",    19 => "11001011100",    20 => "11001001110",
				21 => "11011100100",    22 => "11001110100",    23 => "11101101110",
				24 => "11101001100",    25 => "11100101100",    26 => "11100100110",
				27 => "11101100100",    28 => "11100110100",    29 => "11100110010",
				30 => "11011011000",    31 => "11011000110",    32 => "11000110110",
				33 => "10100011000",    34 => "10001011000",    35 => "10001000110",
				36 => "10110001000",    37 => "10001101000",    38 => "10001100010",
				39 => "11010001000",    40 => "11000101000",    41 => "11000100010",
				42 => "10110111000",    43 => "10110001110",    44 => "10001101110",
				45 => "10111011000",    46 => "10111000110",    47 => "10001110110",
				48 => "11101110110",    49 => "11010001110",    50 => "11000101110",
				51 => "11011101000",    52 => "11011100010",    53 => "11011101110",
				54 => "11101011000",    55 => "11101000110",    56 => "11100010110",
				57 => "11101101000",    58 => "11101100010",    59 => "11100011010",
				60 => "11101111010",    61 => "11001000010",    62 => "11110001010",
				63 => "10100110000",    64 => "10100001100",    65 => "10010110000",
				66 => "10010000110",    67 => "10000101100",    68 => "10000100110",
				69 => "10110010000",    70 => "10110000100",    71 => "10011010000",
				72 => "10011000010",    73 => "10000110100",    74 => "10000110010",
				75 => "11000010010",    76 => "11001010000",    77 => "11110111010",
				78 => "11000010100",    79 => "10001111010",    80 => "10100111100",
				81 => "10010111100",    82 => "10010011110",    83 => "10111100100",
				84 => "10011110100",    85 => "10011110010",    86 => "11110100100",
				87 => "11110010100",    88 => "11110010010",    89 => "11011011110",
				90 => "11011110110",    91 => "11110110110",    92 => "10101111000",
				93 => "10100011110",    94 => "10001011110",    95 => "10111101000",
				96 => "10111100010",    97 => "11110101000",    98 => "11110100010",
				99  => "10111011110",    // 99 et 'c' sont identiques ne nous sert que pour le checksum
				100 => "10111101110",    // 100 et 'b' sont identiques ne nous sert que pour le checksum
				101 => "11101011110",    // 101 et 'a' sont identiques ne nous sert que pour le checksum
				102 => "11110101110",    // 102 correspond à FNC1 ne nous sert que pour le checksum
				'c' => "10111011110",   'b' => "10111101110",   'a' => "11101011110",
				'A' => "11010000100",   'B' => "11010010000",   'C' => "11010011100",
				'S' => "1100011101011"
			);
	
    var $C25 =  array(
                0 => "11331",           1 => "31113",
                2 => "13113",           3 => "33111",
                4 => "11313",           5 => "31311",
                6 => "13311",           7 => "11133",
                8 => "31131",           9 => "13131",
                'D' => "111011101",       'F' => "111010111", // Code 2 parmi 5
                'd' => "1010",          'f' => "11101"   // Code 2/5 entrelacé
			);
				 
    var $C39 =  array(
                '0' => "101001101101",  '1' => "110100101011",  '2' => "101100101011",
                '3' => "110110010101",  '4' => "101001101011",  '5' => "110100110101",
                '6' => "101100110101",  '7' => "101001011011",  '8' => "110100101101",
                '9' => "101100101101",  'A' => "110101001011",  'B' => "101101001011",
                'C' => "110110100101",  'D' => "101011001011",  'E' => "110101100101",
                'F' => "101101100101",  'G' => "101010011011",  'H' => "110101001101",
                'I' => "101101001101",  'J' => "101011001101",  'K' => "110101010011",
                'L' => "101101010011",  'M' => "110110101001",  'N' => "101011010011",
                'O' => "110101101001",  'P' => "101101101001",  'Q' => "101010110011",
                'R' => "110101011001",  'S' => "101101011001",  'T' => "101011011001",
                'U' => "110010101011",  'V' => "100110101011",  'W' => "110011010101",
                'X' => "100101101011",  'Y' => "110010110101",  'Z' => "100110110101",
                '-' => "100101011011",  '.' => "110010101101",  ' ' => "100110101101",
                '$' => "100100100101",  '/' => "100100101001",  '+' => "100101001001",
                '%' => "101001001001",  '*' => "100101101101"
			);
				 
    var $codabar = array(
                '0' => "101010011",     '1' => "101011001",     '2' => "101001011",
                '3' => "110010101",     '4' => "101101001",     '5' => "110101001",
                '6' => "100101011",     '7' => "100101101",     '8' => "100110101",
                '9' => "110100101",     '-' => "101001101",     '$' => "101100101",
                ':' => "1101011011",    '/' => "1101101011",    '.' => "1101101101",
                '+' => "1011011011",    'A' => "1011001001",    'B' => "1010010011",
                'C' => "1001001011",    'D' => "1010011001"
			);
			
    var $MSI = array(
                0 => "100100100100", 
                1 => "100100100110", 
                2 => "100100110100", 
                3 => "100100110110", 
                4 => "100110100100", 
                5 => "100110100110", 
                6 => "100110110100", 
                7 => "100110110110", 
                8 => "110100100100", 
                9 => "110100100110", 
                'D' => "110", 
                'F' => "1001"
			);
				 
    var $C11 = array(
                '0' => "101011", 
                '1' => "1101011", 
                '2' => "1001011", 
                '3' => "1100101", 
                '4' => "1011011", 
                '5' => "1101101", 
                '6' => "1001101", 
                '7' => "1010011", 
                '8' => "1101001", 
                '9' => "110101", 
                '-' => "101101", 
                'S' => "1011001" 
			);

    var $postnet = array(
                '0' => "11000", 
                '1' => "00011", 
                '2' => "00101", 
                '3' => "00110", 
                '4' => "01001", 
                '5' => "01010", 
                '6' => "01100", 
                '7' => "10001", 
                '8' => "10010", 
                '9' => "10100"
			);

    var $kix = array(       //0=haut, 1=bas, 2=milieu, 3=toute la hauteur
                '0' => '2233',          '1' => '2103',          '2' => '2130',
                '3' => '1203',          '4' => '1230',          '5' => '1100',
                '6' => '2013',          '7' => '2323',          '8' => '2310',
				'9' => '1023',          'A' => '1010',          'B' => '1320',
                'C' => '2031',          'D' => '2301',          'E' => '2332',
				'F' => '1001',          'G' => '1032',          'H' => '1302',
                'I' => '0213',          'J' => '0123',          'K' => '0110',
				'L' => '3223',          '2' => '3210',          'N' => '3120',
                'O' => '0231',          'P' => '0101',          'Q' => '0132',
                'R' => '3201',          'S' => '3232',          'T' => '3102',
                'U' => '0011',          'V' => '0321',          'W' => '0312',
                'X' => '3021',          'Y' => '3021',          'Z' => '3322'
			);

    var $CMC7 = array(
                0 => "0,3-0,22|2,1-2,24|4,0-4,8|4,18-4,25|8,0-8,8|8,18-8,25|12,0-12,8|12,18-12,25|14,1-14,24|16,3-16,22",
                1 => "0,5-0,12|0,17-0,25|4,3-4,10|4,17-4,25|6,2-6,9|6,17-6,25|8,1-8,25|10,0-10,25|14,14-14,25|16,14-16,25",
                2 => "0,2-0,9|0,17-0,25|2,0-2,9|2,16-2,25|6,0-6,6|6,13-6,25|10,0-10,6|10,11-10,17|10,20-10,25|12,0-12,6|12,10-12,16|12,20-12,25|14,0-14,14|14,20-14,25|16,2-16,13|16,20-16,25",
                3 => "0,2-0,9|0,17-0,23|4,0-4,9|4,17-4,25|6,0-6,8|6,18-6,25|10,0-10,7|10,10-10,16|10,19-10,25|12,0-12,7|12,10-12,16|12,19-12,25|14,0-14,25|16,2-16,12|16,14-16,23",
                4 => "0,6-0,21|4,4-4,21|6,3-6,11|6,16-6,21|8,2-8,10|8,16-8,21|12,0-12,8|12,15-12,25|14,0-14,8|14,15-14,25|16,0-16,8|16,15-16,25",
                5 => "0,0-0,14|0,19-0,25|2,0-2,14|2,19-2,25|4,0-4,6|4,9-4,14|4,19-4,25|6,0-6,6|6,9-6,14|6,19-6,25|10,0-10,6|10,9-10,14|10,19-10,25|14,0-14,6|14,9-14,25|16,0-16,6|16,11-16,23",
                6 => "0,2-0,23|2,0-2,25|4,0-4,6|4,10-4,15|4,19-4,25|8,0-8,6|8,10-8,15|8,19-8,25|10,0-10,6|10,10-10,15|10,19-10,25|14,0-14,7|14,10-14,25|16,2-16,7|16,12-16,23",
                7 => "0,0-0,9|0,19-0,25|4,0-4,6|4,16-4,25|8,0-8,6|8,12-8,21|10,0-10,6|10,9-10,19|12,0-12,17|14,0-14,15|16,0-16,13",
                8 => "0,2-0,10|0,15-0,23|2,0-2,11|2,14-2,25|6,0-6,6|6,10-6,15|6,19-6,25|8,0-8,6|8,10-8,15|8,19-8,25|10,0-10,6|10,10-10,15|10,19-10,25|14,0-14,11|14,14-14,25|16,2-16,10|16,15-16,23",
                9 => "0,2-0,13|0,18-0,23|2,0-2,15|2,18-2,25|6,0-6,6|6,10-6,15|6,19-6,25|8,0-8,6|8,10-8,15|8,19-8,25|12,0-12,6|12,10-12,15|12,19-12,25|14,0-14,25|16,2-16,23",
                'A' => "0,4-0,15|0,19-0,24|2,4-2,15|2,19-2,24|4,4-4,15|4,19-4,24|8,4-8,15|8,19-8,24|10,4-10,15|10,19-10,24|12,4-12,15|12,19-12,24|16,4-16,15|16,19-16,24",
                'B' => "0,9-0,24|4,7-4,22|6,6-6,21|8,5-8,20|10,4-10,19|12,3-12,18|16,1-16,16",
                'C' => "0,4-0,12|0,16-0,24|2,4-2,12|2,16-2,24|4,4-4,12|4,16-4,24|6,4-6,12|6,16-6,24|10,7-10,21|12,7-12,21|16,7-16,21",
                'D' => "0,10-0,24|2,10-2,24|6,10-6,24|8,10-8,24|10,4-10,24|12,4-12,24|16,4-16,24",
                'E' => "0,7-0,12|0,16-0,25|2,5-2,23|4,3-4,21|6,1-6,19|8,0-8,18|12,3-12,21|16,7-16,12|16,16-16,25",
			);
			
    var $EANbars = array('A' => array(
                0 => "0001101",         1 => "0011001",
                2 => "0010011",         3 => "0111101",
                4 => "0100011",         5 => "0110001",
                6 => "0101111",         7 => "0111011",
                8 => "0110111",         9 => "0001011"
                ),
                'B' => array(
                0 => "0100111",         1 => "0110011",
                2 => "0011011",         3 => "0100001",
                4 => "0011101",         5 => "0111001",
                6 => "0000101",         7 => "0010001",
                8 => "0001001",         9 => "0010111"
                ),
                'C' => array(
                0 => "1110010",         1 => "1100110",
                2 => "1101100",         3 => "1000010",
                4 => "1011100",         5 => "1001110",
                6 => "1010000",         7 => "1000100",
                8 => "1001000",         9 => "1110100"
                )
            );
    
    var $EANparity = array(
                0 => array('A','A','A','A','A','A'),
                1 => array('A','A','B','A','B','B'),
                2 => array('A','A','B','B','A','B'),
                3 => array('A','A','B','B','B','A'),
                4 => array('A','B','A','A','B','B'),
                5 => array('A','B','B','A','A','B'),
                6 => array('A','B','B','B','A','A'),
                7 => array('A','B','A','B','A','B'),
                8 => array('A','B','A','B','B','A'),
                9 => array('A','B','B','A','B','A')
            );
    
    /**
    * Constructeur
    *
    * Initialise la classe
    *
    * @CODE            string        code CODE
    *
    * return            void
    */
    function pi_barcode($TYPE, $CODE, $HEIGHT=10, $WIDTH=0, $HR="Y",  $SHOWTYPE="N")
    {
		$this->TYPE = $TYPE;
		$this->HEIGHT = $HEIGHT;
		$this->WIDTH = $WIDTH;
		if( $HR == "Y" ) $this->HR = $CODE;
		$this->SHOWTYPE = $SHOWTYPE;
		
        settype($CODE,'string');
        
		$lencode = strlen($CODE);
    $strCode="";
        //Transformation de la chaine en tableau
        for($i=0; $i < $lencode ; $i++)
        {
            $this->CODE[$i] = substr($CODE,$i,1);
        }

		switch( $TYPE ) {
		
			case "EAN" :
			case "UPC" :
				if( $lencode == 8 ) {
                    $strCode = '101'; //Premier séparateur (101)
                    for ($i=0; $i<4; $i++) $strCode .= $this->EANbars['A'][$this->CODE[$i]]; //Codage partie gauche (tous de classe A)
                    $strCode .= '01010'; //Séparateur central (01010) //Codage partie droite (tous de classe C)
                    for ($i=4; $i<8; $i++) $strCode .= $this->EANbars['C'][$this->CODE[$i]];
                    $strCode .= '101'; //Dernier séparateur (101)
				} else {
                    $parity = $this->EANparity[$this->CODE[0]]; //On récupère la classe de codage de la partie qauche
                    $strCode = '101'; //Premier séparateur (101)
                    for ($i=1; $i<7; $i++) $strCode .= $this->EANbars[$parity[$i-1]][$this->CODE[$i]]; //Codage partie gauche
                    $strCode .= '01010'; //Séparateur central (01010) //Codage partie droite (tous de classe C)
                    for ($i=7; $i<13; $i++) $strCode .= $this->EANbars['C'][$this->CODE[$i]];
                    $strCode .= '101'; //Dernier séparateur (101)
				}
    
			  break;
			case "C128C" :
                $strCode = $this->C128['C']; //Start
				$checksum = 105 ;
				$j = 1 ;
			    for($i=0;$i<strlen($CODE);$i+=2) {
				    $tmp = intval(substr($CODE, $i, 2)) ;
					$checksum += ( $j++ * $tmp ) ;
				    $strCode .= $this->C128[$tmp];
				}
				$checksum %= 103 ;
				$strCode .= $this->C128[$checksum];
                $strCode .= $this->C128['S']; //Stop
			  break;
			case "C128" :
                $strCode = $this->C128['B']; //Start
				$checksum = 104 ;
				$j = 1 ;
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = ord($this->CODE[$i]) - 32 ;
					$checksum += ( $j++ * $tmp ) ;
				    $strCode .= $this->C128[$tmp];
				}
				$checksum %= 103 ;
				$strCode .= $this->C128[$checksum];
                $strCode .= $this->C128['S']; //Stop
			  break;
			case "C25" :
                $strCode = $this->C25['D']."0"; //Start
			    for($i=0;$i<$lencode;$i++) {
				    $num = intval($this->CODE[$i]) ;
					$tmp = $this->C25[$num];
    			    for($j=0;$j<5;$j++) {
    				    $tmp2 = intval(substr($tmp,$j,1)) ;
    				    for($k=1;$k<=$tmp2;$k++) $strCode .= "1";
						$strCode .= "0";
    				}
				}
                $strCode .= $this->C25['F']; //Stop
			  break;
			case "C25I" :
                $strCode = $this->C25['d']; //Start
				$checksum = 0;
			    for($i=0;$i<$lencode;$i+=2) {
				    $num1 = intval($this->CODE[$i]) ;
				    $num2 = intval($this->CODE[$i+1]) ;
					$checksum += ($num1+$num2);
					$tmp1 = $this->C25[$num1];
					$tmp2 = $this->C25[$num2];
    			    for($j=0;$j<5;$j++) {
    				    $t1 = intval(substr($tmp1,$j,1)) ;
    				    $t2 = intval(substr($tmp2,$j,1)) ;
    				    for($k=1;$k<=$t1;$k++) $strCode .= "1";
    				    for($k=1;$k<=$t2;$k++) $strCode .= "0";
    				}
				}
                $strCode .= $this->C25['f']; //Stop
			  break;
			case "C39" :
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = $this->CODE[$i];
				    $strCode .= $this->C39[$tmp] . "0";
				}
				$strCode = substr($strCode,0,-1);
			  break;
			case "CODABAR" :
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = $this->CODE[$i];
				    $strCode .= $this->codabar[$tmp] . "0";
				}
				$strCode = substr($strCode,0,-1);
			  break;
			case "MSI" :
                $strCode = $this->MSI['D']; //Start
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = intval($this->CODE[$i]);
				    $strCode .= $this->MSI[$tmp];
				}
                $strCode .= $this->MSI['F']; //Stop
			  break;
			case "C11" :
                $strCode = $this->C11['S']."0"; //Start
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = $this->CODE[$i];
				    $strCode .= $this->C11[$tmp]."0";
				}
                $strCode .= $this->C11['S']; //Stop
			  break;
			case "POSTNET" :
                $strCode = "1"; //Start
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = $this->CODE[$i];
				    $strCode .= $this->postnet[$tmp];
				}
                $strCode .= "1"; //Stop
				
				$tmp = ( strlen($strCode) * 4 ) + 20;
		        if( $HR == "Y" ) $this->HEIGHT = 32;
				else $this->HEIGHT = 22;
				$this->WIDTH = $tmp;
			  break;
			case "KIX" :
//                $strCode = "31"; //Start
                $strCode = "";
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = $this->CODE[$i];
				    $strCode .= $this->kix[$tmp];
				}
//                $strCode .= "32"; //Stop
				
				$tmp = ( strlen($strCode) * 4 ) + 20;
		        if( $HR == "Y" ) $this->HEIGHT = 32;
				else $this->HEIGHT = 22;
				$this->WIDTH = $tmp;
			  break;
			case "CMC7" :
                $strCode = "";
			    for($i=0;$i<$lencode;$i++) {
				    $tmp = $this->CODE[$i];
					
				    $strCode .= $tmp;
				}
								
				$this->WIDTH = ( strlen($CODE) * 24 ) + 12 ;
		        $this->HEIGHT = 35;
			  break;
			case "ERR" :
				$this->HEIGHT = 36;
				$this->WIDTH = 200;
			  break;
			  
		}

        $this->strCode = $strCode;
		$tmp = strlen($this->strCode) + 20;
		if($this->WIDTH < $tmp) $this->WIDTH = $tmp;
    }
    
    
    /**
    * Création de l'image
    *
    * Crée une image GIF ou PNG du code généré par giveCode
    *
    * return            void
    */
    function makeImage()
    {
        //Initialisation de l'image
        $posX = 0; // position X
        $posY = 0; // position Y
        $intL = 1; // largeur de la barre
		$nb_elem = strlen($this->strCode);
        
        $img=imagecreate($this->WIDTH, $this->HEIGHT);
        
        $color[0] = ImageColorAllocate($img, 255,255,255);
        $color[1] = ImageColorAllocate($img, 0,0,0);
        $color[2] = ImageColorAllocate($img, 160,160,160);
        
        imagefilledrectangle($img, 0, 0, $nb_elem, $this->HEIGHT, $color[0]);
        
        for($i=0;$i<$nb_elem;$i++)
        {
		
            $intH = $this->HEIGHT; // hauteur du code
			
            if( $this->HR != "" ) switch($this->TYPE){
		      case "EAN" :
		      case "UPC" :
				if($i<=2 OR $i>=($nb_elem-3) OR ($i>=($nb_elem/2)-2 AND $i<=($nb_elem/2)+2)) $intH-=6; else $intH-=11;
              break;
		      default :
				if($i>0 AND $i<($nb_elem-1)) $intH-=11;
			}
            
            $fill_color = substr($this->strCode,$i,1);
            
			if($this->TYPE == "POSTNET") {
			    if($fill_color == "1") imagefilledrectangle($img, $posX, ($posY+1), $posX+1, ($posY+20), $color[1]);
			    else imagefilledrectangle($img, $posX, ($posY+12), $posX+1, ($posY+20), $color[1]);
				$intL = 4 ;
			} elseif($this->TYPE == "KIX") {
			    if($fill_color == "0") imagefilledrectangle($img, $posX, ($posY+1), $posX+1, ($posY+13), $color[1]);
			    elseif($fill_color == "1") imagefilledrectangle($img, $posX, ($posY+7), $posX+1, ($posY+19), $color[1]);
			    elseif($fill_color == "2") imagefilledrectangle($img, $posX, ($posY+7), $posX+1, ($posY+13), $color[1]);
			    else imagefilledrectangle($img, $posX, ($posY+1), $posX+1, ($posY+19), $color[1]);
				$intL = 4 ;
			} elseif($this->TYPE == "CMC7") {
			
				$tmp = $this->CMC7[$fill_color];
                $coord = explode( "|", $tmp );
				
                for( $j=0; $j<sizeof($coord); $j++) {
                	$pts = explode( "-", $coord[$j] );
                	$deb = explode( ",", $pts[0] );
                	$X1 = $deb[0] + $posX ;
                	$Y1 = $deb[1] + 5 ;
                	$fin = explode( ",", $pts[1] );
                	$X2 = $fin[0] + $posX ;
                	$Y2 = $fin[1] + 5 ;
                	
                	imagefilledrectangle($img, $X1, $Y1, $X2, $Y2, $color[1]);
                }
                $intL = 24 ;
            } 
    		else  {
			    if($fill_color == "1") imagefilledrectangle($img, $posX, $posY, $posX, ($posY+$intH), $color[1]);
			}
//            imagefilledrectangle($img, $posX, $posY, $posX, ($posY+$intH), $color[$fill_color]);
            
            //Deplacement du pointeur
            $posX += $intL;
        }
        
        $ifw = imagefontwidth(3);
        $ifh = imagefontheight(3) - 1;
        switch($this->TYPE){
		  case "ERR" :
			$ifw = imagefontwidth(3);
            imagestring($img, 3, floor(($this->WIDTH/2)-(($ifw * 7)/2)), 1, "ERROR :", $color[1]); 
			$ifw = imagefontwidth(2);
            imagestring($img, 2, floor(($this->WIDTH/2)-(($ifw * strlen(implode('',$this->CODE)))/2)), 13, implode('',$this->CODE), $color[1]); 
			$ifw = imagefontwidth(1);
            imagestring($img, 1, ($this->WIDTH)-($ifw * 9)-2, 26, "Pitoo.com", $color[2]); 
          break;
		  case "EAN" :
                if(strlen($this->HR) > 10) imagestring($img, 3, 3, $this->HEIGHT - $ifh, substr($this->HR,-13,1), $color[1]); 
		  case "UPC" :
		    if(strlen($this->HR) > 10) {
                imagestring($img, 3, 14, $this->HEIGHT - $ifh, substr($this->HR,1,6), $color[1]); 
                imagestring($img, 3, 60, $this->HEIGHT - $ifh, substr($this->HR,7,6), $color[1]); 
		    } else {
                imagestring($img, 3, 14, $this->HEIGHT - $ifh, substr($this->HR,0,4), $color[1]); 
                imagestring($img, 3, 46, $this->HEIGHT - $ifh, substr($this->HR,4,4), $color[1]); 
		    }
          break;
		  case "CMC7" ;
		  break;
		  default :
			$ifw = imagefontwidth(3);
			$ifh = imagefontheight(3) - 1;
            imagestring($img, 3, intval(($this->WIDTH/2)-(($ifw * strlen($this->HR))/2))+1, $this->HEIGHT - $ifh, $this->HR, $color[1]); 
        }
        
		$ifw = imagefontwidth(1) * 9;
        if( (rand(0,50)<1) AND ($this->HEIGHT >= $ifw) ) {
		    imagestringup($img, 1, $nb_elem + 12, $this->HEIGHT - 2, "Pitoo.com", $color[2]); 
		}
        if( $this->SHOWTYPE == "Y" ) {
			if(($this->TYPE == "EAN") AND (substr($this->HR,-13,1) != "0") AND (strlen($this->HR) > 10)) {
		        imagestringup($img, 1, 0, $this->HEIGHT - 12, $this->TYPE, $color[2]); 
			} elseif($this->TYPE == "POSTNET") {
		        imagestringup($img, 1, 0, $this->HEIGHT - 2, "POST", $color[2]); 
			} else {
		        imagestringup($img, 1, 0, $this->HEIGHT - 2, $this->TYPE, $color[2]); 
			}
		}
        

        Header( "Content-type: image/png"); 
        imagepng($img); 
        imagedestroy($img); 
    }
    
    
}//Fin de la classe
J'ai mis en gras l'endroit où elle me sort le PNG du code barre. J'ai tenté d'appeler cette classe avec un include depuis FPDF, j'ai essayé avec imagecopyresized, imagefrompng, etc. mais rien n'y fait. J'ai aussi tenté d'ajouter un second paramètre à imagepng($img, $filename) mais il ne se passe rien.

Quelqu'un aurait-il une piste à me donner pour adapter ce script afin qu'il me copie l'image générée quelque part? Je sèche...

Merci pour ton remarque et aide que vs pourrez me procurer...


Semias
semias est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 14h48   #2
Membre chevronné
 
Avatar de Spoutnik
 
Homme
Inscription : octobre 2003
Messages : 668
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Etats-Unis

Informations forums :
Inscription : octobre 2003
Messages : 668
Points : 746
Points : 746
la fonction " imagepng($img); " peut prendre un deuxième paramètre qui correspond au nom de fichier ou sera enregistré l'image.
cf la page de manuel
++
__________________
Two beer or not two beer. (Shakesbeer)
Question technique par MP => poubelle!
Spoutnik est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 14h55   #3
Invité de passage
 
Inscription : mai 2008
Messages : 5
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 5
Points : 1
Points : 1
Merci Spoutnik, mais comme je le disais ds mon post:

Citation:
J'ai aussi tenté d'ajouter un second paramètre à imagepng($img, $filename) mais il ne se passe rien.
J'ai tenté avec chemin relatif et absolu, mais il ne se passe rien...
semias est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 15h11   #4
Membre chevronné
 
Avatar de Spoutnik
 
Homme
Inscription : octobre 2003
Messages : 668
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Etats-Unis

Informations forums :
Inscription : octobre 2003
Messages : 668
Points : 746
Points : 746
Citation:
Envoyé par semias Voir le message
Merci Spoutnik, mais comme je le disais ds mon post:
J'ai tenté avec chemin relatif et absolu, mais il ne se passe rien...
décidement, je lis trop vite en ce moment.

Essaye de virer le Header. Si tu l'envoie sur un fichier, tu dois pas en avoir besoin.
Et sinon, vérifie que tu as tous les droits d'écriture sur le fichier destination (donc le fichier + ses parents).
__________________
Two beer or not two beer. (Shakesbeer)
Question technique par MP => poubelle!
Spoutnik est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 15h41   #5
Invité de passage
 
Inscription : mai 2008
Messages : 5
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 5
Points : 1
Points : 1
J'ai déjà essayé, sans succès

J'inclus le fichier comme ça dans FPDF :

$url = "includes/pi_barcode.php?type=C128C&code=".$codebarre."&height=60";

include ($url);

Et dans le script lui-même (pi_barcode):

imagepng($img, "image.png")

Ensuite je regarde sur le serveur mais il ne m'a rien copié t
semias est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 15h58   #6
Membre chevronné
 
Avatar de Spoutnik
 
Homme
Inscription : octobre 2003
Messages : 668
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Etats-Unis

Informations forums :
Inscription : octobre 2003
Messages : 668
Points : 746
Points : 746
Citation:
Envoyé par semias Voir le message
$url = "includes/pi_barcode.php?type=C128C&code=".$codebarre."&height=60";
include ($url);
Ca risque pas de marcher Dans ton cas, le serveur cherche un fichier qui s'appelle "pi_barcode.php?type=C128C&code=12346&height=60" (c'est un exemple) mais en aucun cas il n'interprète le script pi_barcode.php avec les paramètres type, code, etc ...
cf le manuel de include Exemple #3

si tu fais
include "http://www.example.com/includes/pi_barcode.php?type=C128C&code=".$codebarre."&height=60"; ca devrait marcher

Mais plutot que de faire ceci, tu devrais récupérer le code en dessous de la définition de la classe dans le fichier pi_barcode et créer l'objet pi_barche dans ta classe/appel FPDF, qq chose du genre :

Code :
1
2
3
4
5
6
7
8
9
10
11
 
include 'includes/pi_barcode.php';
 
class myFPDF extends FPDF{
...
  function generateBarCode( $type, $code, $hh, $hr, $hw, $showtype ){
    $objCode = new pi_barcode( $type, $code, $hh, $hr, $hw, $showtype ) ;
    $objCode -> makeImage() ;
  }
...
}
__________________
Two beer or not two beer. (Shakesbeer)
Question technique par MP => poubelle!
Spoutnik est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 16h22   #7
Invité de passage
 
Inscription : mai 2008
Messages : 5
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 5
Points : 1
Points : 1
Merci encore Spoutnik. J'ai ce code actuellement:

Code :
1
2
3
4
5
6
7
8
9
10
11
include 'includes/pi_barcode.php';
 
class myFPDF extends FPDF{
 
  function generateBarCode( $type, $code, $hh, $hr, $hw, $showtype ){
    $objCode = new pi_barcode( $type, $code, $hh, $hr, $hw, $showtype ) ;
    $objCode -> makeImage() ;
  }
 
}
$pdf->myPDF('C128C',$codebarre, 60, '', '', '');
Le truc, c'est que je suis pas sûr de savoir quels paramètres donner. Maintenant, FPDF n'outputte rien, mais l'image est créée. Cependant, il me crée une image avec un message d'erreur, comme quoi mon code n'est pas valide.


J'ai un peu changé le code de pi_barcode (pour qu'il "outputte" en silence):

Code :
$test = imagepng($img, "imagesss.png");
semias est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 16h36   #8
Invité de passage
 
Inscription : mai 2008
Messages : 5
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 5
Points : 1
Points : 1
OK, j'ai fait 2-3 bidouillages, et Ô miracle, ça marche!


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
$type = 'C128C';
$code = $codebarre;
$height = 60;
include 'includes/pi_barcode.php';
 
class myFPDF extends FPDF{
 
  function generateBarCode( $type, $code, $hh, $hr, $hw, $showtype ){
    $objCode = new pi_barcode( $type, $code, $hh, $hr, $hw, $showtype ) ;
    $objCode -> makeImage() ;
  }
 
}

Je te suis redevable à vie Spoutnik!!!
semias est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/05/2008, 16h37   #9
Membre chevronné
 
Avatar de Spoutnik
 
Homme
Inscription : octobre 2003
Messages : 668
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Etats-Unis

Informations forums :
Inscription : octobre 2003
Messages : 668
Points : 746
Points : 746
[edit] bah si ca marche, plus besoin de mon message !![/edit]

Ravi d'avoir pu t'aider!

Edit 2 :
Un poil plus propre :

Code :
1
2
3
4
5
6
7
include 'includes/pi_barcode.php';
class myFPDF extends FPDF{
  function generateBarCode( $type='C128C', $code=$codebarre, $hh=60, $hr, $hw, $showtype ){
    $objCode = new pi_barcode( $type, $code, $hh, $hr, $hw, $showtype ) ;
    $objCode -> makeImage() ;
  }
}
Edit3 : Tu voudrais pas mettre le fichier qui contient la classe "myPDF" en pièce jointe à ce message? ton code me parait étrange à priori.
__________________
Two beer or not two beer. (Shakesbeer)
Question technique par MP => poubelle!
Spoutnik est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2008, 16h17   #10
Invité de passage
 
Inscription : mai 2007
Messages : 9
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 9
Points : 1
Points : 1
Bonjour,
je suis dans le même cas, j'utilise la classe pi_barcode avec fpdf.

J'ai suivi vos instructions mais je ne comprend pas tout. J'ai mis la methode generateBarCode dans ma classe qui extend fpdf et je l'appelle comme suit:
Code :
$pdf->generateBarCode( $type, $codebarre, $hcode, 'Y', '0', 'N' ) ;
Vouc vous appellez la classe, pourquoi?

Et donc voici mon code:
Code :
1
2
3
4
5
6
7
8
9
10
 
include('pdf.php');
include('pi_barcode.php');
class PDF extends FPDF{
....
    function generateBarCode( $type, $code, $hh, $hr, $hw, $showtype ){
         $objCode = new pi_barcode( $type, $code, $hh, $hr, $hw, $showtype ) ;
         $objCode -> makeImage() ;
  }
}
puis au moment ou je veut le mettre dans le pdf:
Code :
1
2
3
4
5
6
7
 
$type='EAN';
if(isset($_POST['chiffre'])){
	$pdf->generateBarCode( $type, $codebarre, $hcode, 'Y', '0', 'N' ) ;
}else{
	$pdf->generateBarCode( $type, $codebarre, $hcode, 'N', '0', 'N' ) ;
}
J'ai rien modifier dans pi_barcode.php et j'ai l'erreur suivante lorsque j'execute:

Notice: Undefined variable: type in c:\program files\easyphp1-8\www\testcode\pi_barcode.php on line 570

puis:

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\testcode\format_pdf.php:10) in c:\program files\easyphp1-8\www\toutpack\pi_barcode.php on line 561
‰PNG  ��� IHDR���È���$���±°ô��� PLTEÿÿÿ��� ßøë<���IDATxœÝѱnÄ `'2ËMÂŽ:E} #™Ý‘Âû ¦>Æ÷˜5GNºJ‡ KÕÖb`àÿà_×ÃaÅú8@Șu•Ý“n‡‰‘Þ`FƒÉa¤‹X’ýè;~Í%{"ÃãÇ Äúñ¿4&¿£ˆQ—E$‚'±F¢îõs_“€U ù¥î �õnt 葉¹rN2-MÂÌwÂO+ ¯?HBáˆøè¢sa«ËZƒù{0~"Ô&ʪÄ#~KÊóúÅjò:‹?¹Æ#ÿÉz‡”‰K0Lr¾n€Û¶õÒ,»4C~s½] }dm5Bæ«Û.sºm®—ü|}@×E"+*vþ����IEND®B`‚ Array ( [Hcode] => 12 [H1] => 30 [L1] => 30 [L2] => 30 [H2] => 10 [L3] => 10 )

voila jespère que vous pourez m'aidez. Merci
tantor est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h58.


 
 
 
 
Partenaires

Hébergement Web