forked from ProyectoADSIfredy/ejemploSubirArchivo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
899 lines (743 loc) · 47 KB
/
upload.php
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
<?php
error_reporting(E_ALL);
// we first include the upload class, as we will need it here to deal with the uploaded file
include('class.upload.php');
// set variables
$dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : 'tmp');
$dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv=content-type content="text/html; charset=UTF-8">
<head>
<title>class.php.upload test forms</title>
<style>
body {
}
p.result {
width: 50%;
margin: 15px 0px 25px 0px;
padding: 0px;
clear: right;
}
img {
float: right;
background: url(bg.gif);
}
fieldset {
width: 50%;
margin: 15px 0px 25px 0px;
padding: 15px;
}
legend {
font-weight: bold;
}
fieldset p {
font-size: 70%;
font-style: italic;
}
.button {
text-align: right;
}
.button input {
font-weight: bold;
}
</style>
</head>
<body>
<h1>class.upload.php test forms</h1>
<?php
// we have three forms on the test page, so we redirect accordingly
if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'simple') {
// ---------- SIMPLE UPLOAD ----------
// we create an instance of the class, giving as argument the PHP object
// corresponding to the file field from the form
// All the uploads are accessible from the PHP object $_FILES
$handle = new Upload($_FILES['my_field']);
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// yes, the file is on the server
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process($dir_dest);
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo '<p class="result">';
echo ' <b>File uploaded with success</b><br />';
echo ' File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>';
echo ' (' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
echo '</p>';
} else {
// one error occured
echo '<p class="result">';
echo ' <b>File not uploaded to the wanted location</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
// we delete the temporary files
$handle-> Clean();
} else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo '<p class="result">';
echo ' <b>File not uploaded on the server</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
} else if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'image') {
// ---------- IMAGE UPLOAD ----------
// we create an instance of the class, giving as argument the PHP object
// corresponding to the file field from the form
// All the uploads are accessible from the PHP object $_FILES
$handle = new Upload($_FILES['my_field']);
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// yes, the file is on the server
// below are some example settings which can be used if the uploaded file is an image.
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 300;
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process($dir_dest);
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo '<p class="result">';
echo ' <b>File uploaded with success</b><br />';
echo ' <img src="'.$dir_pics.'/' . $handle->file_dst_name . '" />';
$info = getimagesize($handle->file_dst_pathname);
echo ' File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>';
echo ' (' . $info['mime'] . ' - ' . $info[0] . ' x ' . $info[1] .' - ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
echo '</p>';
} else {
// one error occured
echo '<p class="result">';
echo ' <b>File not uploaded to the wanted location</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
// we now process the image a second time, with some other settings
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 300;
$handle->image_reflection_height = '25%';
$handle->image_contrast = 50;
$handle->Process($dir_dest);
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo '<p class="result">';
echo ' <b>File uploaded with success</b><br />';
echo ' <img src="'.$dir_pics.'/' . $handle->file_dst_name . '" />';
$info = getimagesize($handle->file_dst_pathname);
echo ' File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>';
echo ' (' . $info['mime'] . ' - ' . $info[0] . ' x ' . $info[1] .' - ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
echo '</p>';
} else {
// one error occured
echo '<p class="result">';
echo ' <b>File not uploaded to the wanted location</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
// we delete the temporary files
$handle-> Clean();
} else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo '<p class="result">';
echo ' <b>File not uploaded on the server</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
} else if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'xhr') {
// ---------- XMLHttpRequest UPLOAD ----------
// we first check if it is a XMLHttpRequest call
if (isset($_SERVER['HTTP_X_FILE_NAME']) && isset($_SERVER['CONTENT_LENGTH'])) {
// we create an instance of the class, feeding in the name of the file
// sent via a XMLHttpRequest request, prefixed with 'php:'
$handle = new Upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);
} else {
// we create an instance of the class, giving as argument the PHP object
// corresponding to the file field from the form
// This is the fallback, using the standard way
$handle = new Upload($_FILES['my_field']);
}
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// yes, the file is on the server
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process($dir_dest);
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo '<p class="result">';
echo ' <b>File uploaded with success</b><br />';
echo ' File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>';
echo ' (' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
echo '</p>';
} else {
// one error occured
echo '<p class="result">';
echo ' <b>File not uploaded to the wanted location</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
// we delete the temporary files
$handle-> Clean();
} else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo '<p class="result">';
echo ' <b>File not uploaded on the server</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
} else if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') {
// ---------- MULTIPLE UPLOADS ----------
// as it is multiple uploads, we will parse the $_FILES array to reorganize it into $files
$files = array();
foreach ($_FILES['my_field'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
// now we can loop through $files, and feed each element to the class
foreach ($files as $file) {
// we instanciate the class for each element of $file
$handle = new Upload($file);
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process($dir_dest);
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo '<p class="result">';
echo ' <b>File uploaded with success</b><br />';
echo ' File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>';
echo ' (' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
echo '</p>';
} else {
// one error occured
echo '<p class="result">';
echo ' <b>File not uploaded to the wanted location</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
} else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo '<p class="result">';
echo ' <b>File not uploaded on the server</b><br />';
echo ' Error: ' . $handle->error . '';
echo '</p>';
}
}
} else if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'local' || isset($_GET['file'])) {
// ---------- LOCAL PROCESSING ----------
//error_reporting(E_ALL ^ (E_NOTICE | E_USER_NOTICE | E_WARNING | E_USER_WARNING));
ini_set("max_execution_time",0);
// we don't upload, we just send a local filename (image)
$handle = new Upload((isset($_POST['my_field']) ? $_POST['my_field'] : (isset($_GET['file']) ? $_GET['file'] : '')));
// then we check if the file has been "uploaded" properly
// in our case, it means if the file is present on the local file system
if ($handle->uploaded) {
// now, we start a serie of processes, with different parameters
// we use a little function TestProcess() to avoid repeting the same code too many times
function TestProcess(&$handle, $title = 'test', $details='') {
global $dir_pics, $dir_dest;
$handle->Process($dir_dest);
if ($handle->processed) {
echo '<fieldset class="classuploadphp">';
echo ' <legend>' . $title . '</legend>';
echo ' <div class="classuploadphppic"><img src="'.$dir_pics.'/' . $handle->file_dst_name . '" />';
$info = getimagesize($handle->file_dst_pathname);
echo ' <p>' . $info['mime'] . ' - ' . $info[0] . ' x ' . $info[1] .' - ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB</p></div>';
if ($details) echo ' <pre class="code php">' . htmlentities($details) . '</pre>';
echo '</fieldset>';
} else {
echo '<fieldset class="classuploadphp">';
echo ' <legend>' . $title . '</legend>';
echo ' Error: ' . $handle->error . '';
if ($details) echo ' <pre class="code php">' . htmlentities($details) . '</pre>';
echo '</fieldset>';
}
}
if (!file_exists($dir_dest)) mkdir($dir_dest);
// -----------
TestProcess($handle, 'original file', '');
// -----------
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 50;
TestProcess($handle, 'width 50, height auto', "\$foo->image_resize = true;\n\$foo->image_ratio_y = true;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_x = true;
$handle->image_y = 50;
TestProcess($handle, 'height 50, width auto', "\$foo->image_resize = true;\n\$foo->image_ratio_x = true;\n\$foo->image_y = 50;");
// -----------
$handle->image_resize = true;
$handle->image_y = 50;
$handle->image_x = 50;
TestProcess($handle, 'height 50, width 50', "\$foo->image_resize = true;\n\$foo->image_y = 50;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio = true;
$handle->image_y = 50;
$handle->image_x = 50;
TestProcess($handle, 'height 50, width 50, keeping ratio', "\$foo->image_resize = true;\n\$foo->image_ratio = true;\n\$foo->image_y = 50;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_crop = true;
$handle->image_y = 50;
$handle->image_x = 50;
TestProcess($handle, '50x50, keeping ratio, cropping excedent', "\$foo->image_resize = true;\n\$foo->image_ratio_crop = true;\n\$foo->image_y = 50;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_crop = 'L';
$handle->image_y = 50;
$handle->image_x = 50;
TestProcess($handle, '50x50, keeping ratio, cropping right excedent', "\$foo->image_resize = true;\n\$foo->image_ratio_crop = 'L';\n\$foo->image_y = 50;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_crop = 'R';
$handle->image_y = 50;
$handle->image_x = 50;
TestProcess($handle, '50x50, keeping ratio, cropping left excedent', "\$foo->image_resize = true;\n\$foo->image_ratio_crop = 'R';\n\$foo->image_y = 50;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_fill = true;
$handle->image_y = 50;
$handle->image_x = 150;
TestProcess($handle, '150x50, keeping ratio, filling in', "\$foo->image_resize = true;\n\$foo->image_ratio_fill = true;\n\$foo->image_y = 50;\n\$foo->image_x = 150;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_fill = 'L';
$handle->image_y = 50;
$handle->image_x = 150;
TestProcess($handle, '150x50, keeping ratio, filling left side', "\$foo->image_resize = true;\n\$foo->image_ratio_fill = 'L';\n\$foo->image_y = 50;\n\$foo->image_x = 150;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_fill = 'R';
$handle->image_y = 150;
$handle->image_x = 100;
$handle->image_background_color = '#FF00FF';
TestProcess($handle, '100x150, keeping ratio, filling top and bottom', "\$foo->image_resize = true;\n\$foo->image_ratio_fill = 'R';\n\$foo->image_y = 150;\n\$foo->image_x = 100;\n\$foo->image_background_color = '#FF00FF';");
// -----------
$handle->image_resize = true;
$handle->image_ratio_crop = true;
$handle->image_y = 50;
$handle->image_x = 50;
$handle->image_crop = '0 10';
TestProcess($handle, 'height 50, width 50, cropped, using ratio_crop', "\$foo->image_resize = true;\n\$foo->image_ratio_crop = true;\n\$foo->image_crop = '0 10';\n\$foo->image_y = 50;\n\$foo->image_x = 50;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_pixels = 25000;
TestProcess($handle, 'calculates x and y, targeting 25000 pixels', "\$foo->image_resize = true;\n\$foo->image_ratio_pixels = 25000;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_pixels = 10000;
TestProcess($handle, 'calculates x and y, targeting 10000 pixels', "\$foo->image_resize = true;\n\$foo->image_ratio_pixels = 10000;");
// -----------
$handle->image_crop = '20%';
TestProcess($handle, '20% crop', "\$foo->image_crop = '20%';");
// -----------
$handle->image_crop = '5 20%';
TestProcess($handle, '5px vertical and 20% horizontal crop', "\$foo->image_crop = '5 20%';");
// -----------
$handle->image_crop = '-3px -10%';
$handle->image_background_color = '#FF00FF';
TestProcess($handle, 'negative crop with a background color', "\$foo->image_crop = '-3px -10%';\n\$foo->image_background_color = '#FF00FF';");
// -----------
$handle->image_crop = '5 40 10% -20';
TestProcess($handle, '5px top, 40px right, 10% bot. and -20px left crop', "\$foo->image_crop = '5 40 10% -20';");
// -----------
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 150;
$handle->image_precrop = 15;
TestProcess($handle, '15px pre-cropping (before resizing 150 wide)', "\$foo->image_resize = true;\n\$foo->image_ratio_y = true;\n\$foo->image_x = 150;\n\$foo->image_precrop = 15;");
// -----------
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 150;
$handle->image_precrop = '25 70 10% -20';
TestProcess($handle, 'diverse pre-cropping (before resizing 150 wide)', "\$foo->image_resize = true;\n\$foo->image_ratio_y = true;\n\$foo->image_x = 150;\n\$foo->image_precrop = '25 70 10% -20';");
// -----------
$handle->image_rotate = '90';
TestProcess($handle, '90 degrees rotation', "\$foo->image_rotate = '90';");
// -----------
$handle->image_rotate = '180';
TestProcess($handle, '180 degrees rotation', "\$foo->image_rotate = '180';");
// -----------
$handle->image_flip = 'H';
TestProcess($handle, 'horizontal flip', "\$foo->image_flip = 'H';");
// -----------
$handle->image_convert = 'gif';
$handle->image_flip = 'V';
TestProcess($handle, 'vertical flip, into GIF file', "\$foo->image_convert = 'gif';\n\$foo->image_flip = 'V';");
// -----------
$handle->image_convert = 'bmp';
$handle->image_default_color = '#00FF00';
$handle->image_rotate = '180';
TestProcess($handle, '180 degrees rotation, into GIF, green bg', "\$foo->image_convert = 'gif';\n\$foo->image_default_color = '#00FF00';\n\$foo->image_rotate = '180';");
// -----------
$handle->image_convert = 'png';
$handle->image_flip = 'H';
$handle->image_rotate = '90';
TestProcess($handle, '90 degrees rotation and horizontal flip, into PNG', "\$foo->image_convert = 'png';\n\$foo->image_flip = 'H';\n\$foo->image_rotate = '90';");
// -----------
$handle->image_bevel = 20;
$handle->image_bevel_color1 = '#FFFFFF';
$handle->image_bevel_color2 = '#000000';
TestProcess($handle, '20px black and white bevel', "\$foo->image_bevel = 20;\n\$foo->image_bevel_color1 = '#FFFFFF';\n\$foo->image_bevel_color2 = '#000000';");
// -----------
$handle->image_bevel = 5;
$handle->image_bevel_color1 = '#FFFFFF';
$handle->image_bevel_color2 = '#FFFFFF';
TestProcess($handle, '5px white bevel (smooth border)', "\$foo->image_bevel = 5;\n\$foo->image_bevel_color1 = '#FFFFFF';\n\$foo->image_bevel_color2 = '#FFFFFF';");
// -----------
$handle->image_border = 5;
$handle->image_border_color = '#FF0000';
TestProcess($handle, '5px red border', "\$foo->image_border = 5;\n\$foo->image_border_color = '#FF0000';");
// -----------
$handle->image_border = 5;
$handle->image_border_color = '#00FF00';
$handle->image_border_opacity = 50;
TestProcess($handle, '5px green semi-transparent border', "\$foo->image_border = 5;\n\$foo->image_border_color = '#00FF00';\n\$foo->image_border_opacity = 50;");
// -----------
$handle->image_border = '5 20 1 25%';
$handle->image_border_color = '#0000FF';
TestProcess($handle, '5px top, 20px right, 1px bot. and 25% left blue border', "\$foo->image_border = '5 20 1 25%';\n\$foo->image_border_color = '#0000FF';");
// -----------
$handle->image_frame = 1;
$handle->image_frame_colors = '#FF0000 #FFFFFF #FFFFFF #0000FF';
TestProcess($handle, 'flat colored frame, 4 px wide', "\$foo->image_frame = 1;\n\$foo->image_frame_colors = '#FF0000 #FFFFFF\n #FFFFFF #0000FF';");
// -----------
$handle->image_frame = 2;
$handle->image_frame_colors = '#FFFFFF #BBBBBB #999999 #FF0000 #666666 #333333 #000000';
TestProcess($handle, 'crossed colored frame, 7 px wide', "\$foo->image_frame = 2;\n\$foo->image_frame_colors = '#FFFFFF #BBBBBB\n #999999 #FF0000\n #666666 #333333\n #000000';");
// -----------
$handle->image_frame = 1;
$handle->image_frame_colors = '#FF0000 #FF00FF #0000FF #000000';
$handle->image_frame_opacity = 25;
TestProcess($handle, 'flat colored frame, 4 px wide, 25% opacity', "\$foo->image_frame = 1;\n\$foo->image_frame_colors = '#FF0000 #FF00FF\n #0000FF #000000';\n\$foo->image_frame_opacity = 25;");
// -----------
$handle->image_border_transparent = 10;
TestProcess($handle, '10px fade-to-transparent border', "\$foo->image_border_transparent = 10;");
// -----------
$handle->image_border_transparent = '10 50 20 60';
TestProcess($handle, 'various fade-to-transparent borders', "\$foo->image_border_transparent = '10 50 20 60';");
// -----------
$handle->image_border_transparent = array(0, 150, 0, 0);
TestProcess($handle, 'right fading-out to transparency mask', "\$foo->image_border_transparent = array(0, 150, 0, 0);");
// -----------
$handle->image_overlay_color = '#FFFFFF';
$handle->image_overlay_opacity = 50;
$handle->image_rotate = '180';
$handle->image_tint_color = '#FF0000';
TestProcess($handle, 'tint and 50% overlay and 180\' rotation', "\$foo->image_overlay_color = '#FFFFFF';\n\$foo->image_overlay_opacity = 50;\n\$foo->image_rotate = '180';\n\$foo->image_tint_color = '#FF0000';");
// -----------
$handle->image_tint_color = '#FF0000';
TestProcess($handle, '#FF0000 tint', "\$foo->image_tint_color = '#FF0000';");
// -----------
$handle->image_overlay_color = '#FF0000';
$handle->image_overlay_opacity = 50;
TestProcess($handle, '50% overlay #FF0000', "\$foo->image_overlay_color = '#FF0000';\n\$foo->image_overlay_opacity = 50;");
// -----------
$handle->image_overlay_color = '#0000FF';
$handle->image_overlay_opacity = 5;
TestProcess($handle, '5% overlay #0000FF', "\$foo->image_overlay_color = '#0000FF';\n\$foo->image_overlay_opacity = 5;");
// -----------
$handle->image_overlay_color = '#FFFFFF';
$handle->image_overlay_opacity = 90;
TestProcess($handle, '90% overlay #FFFFFF', "\$foo->image_overlay_color = '#FFFFFF';\n\$foo->image_overlay_opacity = 90;");
// -----------
$handle->image_brightness = 25;
TestProcess($handle, 'brightness 25', "\$foo->image_brightness = 25;");
// -----------
$handle->image_brightness = -25;
TestProcess($handle, 'brightness -25', "\$foo->image_brightness = -25;");
// -----------
$handle->image_contrast = 75;
TestProcess($handle, 'contrast 75', "\$foo->image_contrast = 75;");
// -----------
$handle->image_opacity = 75;
TestProcess($handle, 'opacity 75', "\$foo->image_opacity = 75;");
// -----------
$handle->image_opacity = 25;
TestProcess($handle, 'opacity 25', "\$foo->image_opacity = 25;");
// -----------
$handle->image_threshold = 20;
TestProcess($handle, 'threshold filter', "\$foo->image_threshold = 20;");
// -----------
$handle->image_greyscale = true;
TestProcess($handle, 'greyscale', "\$foo->image_greyscale = true;");
// -----------
$handle->image_negative = true;
TestProcess($handle, 'negative', "\$foo->image_negative = true;");
// -----------
TestProcess($handle, 'original file, again', '');
// -----------
$handle->image_pixelate = 3;
TestProcess($handle, 'pixelate, 3px block size', "\$foo->image_pixelate = 3;");
// -----------
$handle->image_pixelate = 10;
TestProcess($handle, 'pixelate, 10px block size', "\$foo->image_pixelate = 10;");
// -----------
$handle->image_unsharp = true;
TestProcess($handle, 'unsharp mask, default values', "\$foo->image_unsharp = true;");
// -----------
$handle->image_unsharp = true;
$handle->image_unsharp_amount = 200;
$handle->image_unsharp_radius = 1;
$handle->image_unsharp_threshold = 5;
TestProcess($handle, 'unsharp mask, different values', "\$foo->image_unsharp = true;\n\$foo->image_unsharp_amount = 200;\n\$foo->image_unsharp_radius = 1;\n\$foo->image_unsharp_threshold = 5;");
// -----------
$handle->image_brightness = 75;
$handle->image_resize = true;
$handle->image_y = 200;
$handle->image_x = 100;
$handle->image_rotate = '90';
$handle->image_overlay_color = '#FF0000';
$handle->image_overlay_opacity = 50;
$handle->image_text = 'verot.net';
$handle->image_text_color = '#0000FF';
$handle->image_text_background = '#FFFFFF';
$handle->image_text_position = 'BL';
$handle->image_text_padding_x = 10;
$handle->image_text_padding_y = 2;
TestProcess($handle, 'brightness, resize, rotation, overlay & label', "\$foo->image_brightness = 75;\n\$foo->image_resize = true;\n\$foo->image_y = 200;\n\$foo->image_x = 100;\n\$foo->image_rotate = '90';\n\$foo->image_overlay_color = '#FF0000';\n\$foo->image_overlay_opacity = 50;\n\$foo->image_text = 'verot.net';\n\$foo->image_text_color = '#0000FF';\n\$foo->image_text_background = '#FFFFFF';\n\$foo->image_text_position = 'BL';\n\$foo->image_text_padding_x = 10;\n\$foo->image_text_padding_y = 2;");
// -----------
$handle->image_text = 'verot.net';
$handle->image_text_color = '#000000';
$handle->image_text_opacity = 80;
$handle->image_text_background = '#FFFFFF';
$handle->image_text_background_opacity = 70;
$handle->image_text_font = 5;
$handle->image_text_padding = 20;
TestProcess($handle, 'overlayed transparent label', "\$foo->image_text = 'verot.net';\n\$foo->image_text_color = '#000000';\n\$foo->image_text_opacity = 80;\n\$foo->image_text_background = '#FFFFFF';\n\$foo->image_text_background_opacity = 70;\n\$foo->image_text_font = 5;\n\$foo->image_text_padding = 20;");
// -----------
$handle->image_text = 'verot.net';
$handle->image_text_direction = 'v';
$handle->image_text_background = '#000000';
$handle->image_text_font = 2;
$handle->image_text_position = 'BL';
$handle->image_text_padding_x = 2;
$handle->image_text_padding_y = 8;
TestProcess($handle, 'overlayed vertical plain label bottom left', "\$foo->image_text = 'verot.net';\n\$foo->image_text_direction = 'v';\n\$foo->image_text_background = '#000000';\n\$foo->image_text_font = 2;\n\$foo->image_text_position = 'BL';\n\$foo->image_text_padding_x = 2;\n\$foo->image_text_padding_y = 8;");
// -----------
$handle->image_convert = 'bmp';
$handle->image_text = 'verot.net';
$handle->image_text_direction = 'v';
$handle->image_text_color = '#FFFFFF';
$handle->image_text_background = '#000000';
$handle->image_text_background_opacity = 50;
$handle->image_text_padding = 5;
TestProcess($handle, 'overlayed vertical label, into BMP', "\$foo->image_convert = 'bmp';\n\$foo->image_text = 'verot.net';\n\$foo->image_text_direction = 'v';\n\$foo->image_text_color = '#FFFFFF';\n\$foo->image_text_background = '#000000';\n\$foo->image_text_background_opacity = 50;\n\$foo->image_text_padding = 5;");
// -----------
$handle->image_text = 'verot.net';
$handle->image_text_opacity = 50;
$handle->image_text_background = '#0000FF';
$handle->image_text_x = -5;
$handle->image_text_y = -5;
$handle->image_text_padding = 5;
TestProcess($handle, 'overlayed label with absolute negative position', "\$foo->image_text = 'verot.net';\n\$foo->image_text_opacity = 50;\n\$foo->image_text_background = '#0000FF';\n\$foo->image_text_x = -5;\n\$foo->image_text_y = -5;\n\$foo->image_text_padding = 5;");
// -----------
$handle->image_text = 'verot.net';
$handle->image_text_background = '#0000FF';
$handle->image_text_background_opacity = 25;
$handle->image_text_x = 5;
$handle->image_text_y = 5;
$handle->image_text_padding = 20;
TestProcess($handle, 'overlayed transparent label with absolute position', "\$foo->image_text = 'verot.net';\n\$foo->image_text_background = '#0000FF';\n\$foo->image_text_background_opacity = 25;\n\$foo->image_text_x = 5;\n\$foo->image_text_y = 5;\n\$foo->image_text_padding = 20;");
// -----------
$handle->image_text = "verot.net\nclass\nupload";
$handle->image_text_background = '#000000';
$handle->image_text_background_opacity = 75;
$handle->image_text_font = 1;
$handle->image_text_padding = 10;
TestProcess($handle, 'text label with multiple lines and small font', "\$foo->image_text = \"verot.net\\nclass\\nupload\";\n\$foo->image_text_background = '#000000';\n\$foo->image_text_background_opacity = 75;\n\$foo->image_text_font = 1;\n\$foo->image_text_padding = 10;");
// -----------
$handle->image_text = "verot.net\nclass\nupload";
$handle->image_text_color = '#000000';
$handle->image_text_background = '#FFFFFF';
$handle->image_text_background_opacity = 60;
$handle->image_text_padding = 3;
$handle->image_text_font = 3;
$handle->image_text_alignment = 'R';
$handle->image_text_direction = 'V';
TestProcess($handle, 'vertical multi-lines text, right aligned', "\$foo->image_text = \"verot.net\\nclass\\nupload\";\n\$foo->image_text_color = '#000000';\n\$foo->image_text_background = '#FFFFFF';\n\$foo->image_text_background_opacity = 60;\n\$foo->image_text_padding = 3;\n\$foo->image_text_font = 3;\n\$foo->image_text_alignment = 'R';\n\$foo->image_text_direction = 'V';");
// -----------
$handle->image_text = "verot.net\nclass\nupload";
$handle->image_text_background = '#000000';
$handle->image_text_background_opacity = 50;
$handle->image_text_padding = 10;
$handle->image_text_x = -5;
$handle->image_text_y = -5;
$handle->image_text_line_spacing = 10;
TestProcess($handle, 'text label with 10 pixels of line spacing', "\$foo->image_text = \"verot.net\\nclass\\nupload\";\n\$foo->image_text_background = '#000000';\n\$foo->image_text_background_opacity = 50;\n\$foo->image_text_padding = 10;\n\$foo->image_text_x = -5;\n\$foo->image_text_y = -5;\n\$foo->image_text_line_spacing = 10;");
// -----------
$handle->image_unsharp = true;
$handle->image_border = '0 0 16 0';
$handle->image_border_color = '#000000';
$handle->image_text = 'verot.net';
$handle->image_text_font = 2;
$handle->image_text_position = 'B';
$handle->image_text_padding_y = 2;
TestProcess($handle, 'text label in a black line, plus unsharp mask', "\$foo->image_unsharp = true;\n\$foo->image_border = '0 0 16 0';\n\$foo->image_border_color = '#000000';\n\$foo->image_text = \"verot.net\";\n\$foo->image_text_font = 2;\n\$foo->image_text_position = 'B';\n\$foo->image_text_padding_y = 2;");
// -----------
$handle->image_crop = '-3 -3 -30 -3';
$handle->image_text = '[dst_name] [dst_x]x[dst_y]';
$handle->image_text_background = '#6666ff';
$handle->image_text_color = '#ffffff';
$handle->image_background_color = '#000099';
$handle->image_text_font = 2;
$handle->image_text_y = -7;
$handle->image_text_padding_x = 3;
$handle->image_text_padding_y = 2;
TestProcess($handle, 'using tokens in text labels', "\$foo->image_crop = '-3 -3 -30 -3';\n\$foo->image_text = \"[dst_name] [dst_x]x[dst_y]\";\n\$foo->image_text_background = '#6666ff';\n\$foo->image_text_color = '#ffffff';\n\$foo->image_background_color= '#000099';\n\$foo->image_text_font = 2;\n\$foo->image_text_y = -7;\n\$foo->image_text_padding_x = 3;\n\$foo->image_text_padding_y = 2;");
// -----------
$handle->image_crop = '-15 -15 -240 -15';
$handle->image_text = "token value\n------------- ------------------\nsrc_name [src_name]\nsrc_name_body [src_name_body]\nsrc_name_ext [src_name_ext]\nsrc_pathname [src_pathname]\nsrc_mime [src_mime]\nsrc_type [src_type]\nsrc_bits [src_bits]\nsrc_pixels [src_pixels]\nsrc_size [src_size]\nsrc_size_kb [src_size_kb]\nsrc_size_mb [src_size_mb]\nsrc_size_human [src_size_human]\nsrc_x [src_x]\nsrc_y [src_y]\ndst_path [dst_path]\ndst_name_body [dst_name_body]\ndst_name_ext [dst_name_ext]\ndst_name [dst_name]\ndst_pathname [dst_pathname]\ndst_x [dst_x]\ndst_y [dst_y]\ndate [date]\ntime [time]\nhost [host]\nserver [server]\nip [ip]\ngd_version [gd_version]";
$handle->image_text_alignment = 'L';
$handle->image_text_font = 1;
$handle->image_text_position = 'B';
$handle->image_text_padding_y = 5;
$handle->image_text_color = '#000000';
TestProcess($handle, 'all the tokens available', "\$foo->image_crop = '-15 -15 -240 -15';\n\$foo->image_text = \n \"token value\\n\n ------------- ------------------\\n\n src_name [src_name]\\n\n src_name_body [src_name_body]\\n\n src_name_ext [src_name_ext]\\n\n src_pathname [src_pathname]\\n\n src_mime [src_mime]\\n\n src_type [src_type]\\n\n src_bits [src_bits]\\n\n src_pixels [src_pixels]\\n\n src_size [src_size]\\n\n src_size_kb [src_size_kb]\\n\n src_size_mb [src_size_mb]\\n\n src_size_human [src_size_human]\\n\n src_x [src_x]\\n\n src_y [src_y]\\n\n dst_path [dst_path]\\n\n dst_name_body [dst_name_body]\\n\n dst_name_ext [dst_name_ext]\\n\n dst_name [dst_name]\\n\n dst_pathname [dst_pathname]\\n\n dst_x [dst_x]\\n\n dst_y [dst_y]\\n\n date [date]\\n\n time [time]\\n\n host [host]\\n\n server [server]\\n\n ip [ip]\\n\n gd_version [gd_version]\";\n\$foo->image_text_alignment = 'L';\n\$foo->image_text_font = 1;\n\$foo->image_text_position = 'B';\n\$foo->image_text_padding_y = 5;\n\$foo->image_text_color = '#000000';");
// -----------
$handle->image_text = "verot.net\nclass\nupload";
$handle->image_text_background = '#000000';
$handle->image_text_padding = 10;
$handle->image_text_font = "foo.gdf";
$handle->image_text_line_spacing = 2;
TestProcess($handle, 'text label with external GDF font', "\$foo->image_text = \"verot.net\\nclass\\nupload\";\n\$foo->image_text_background = '#000000';\n\$foo->image_text_padding = 10;\n\$foo->image_text_font = \"foo.gdf\";\n\$foo->image_text_line_spacing = 2;");
// -----------
$handle->image_text = "PHP";
$handle->image_text_color = '#FFFF00';
$handle->image_text_background = '#FF0000';
$handle->image_text_padding = 10;
$handle->image_text_font = "foo.gdf";
TestProcess($handle, 'text label with external GDF font', "\$foo->image_text = 'PHP';\n\$foo->image_text_color = '#FFFF00';\n\$foo->image_text_background = '#FF0000';\n\$foo->image_text_padding = 10;\n\$foo->image_text_font = \"foo.gdf\";");
// -----------
$handle->image_reflection_height = '40px';
TestProcess($handle, '40px reflection', "\$foo->image_reflection_height = '40px';");
// -----------
$handle->image_reflection_height = '50%';
$handle->image_text = "verot.net\nclass\nupload";
$handle->image_text_background = '#000000';
$handle->image_text_padding = 10;
$handle->image_text_line_spacing = 10;
TestProcess($handle, 'text label and 50% reflection', "\$foo->image_text = \"verot.net\\nclass\\nupload\";\n\$foo->image_text_background = '#000000';\n\$foo->image_text_padding = 10;\n\$foo->image_text_line_spacing = 10;\n\$foo->image_reflection_height = '50%';");
// -----------
$handle->image_convert = 'jpg';
$handle->image_reflection_height = '40px';
$handle->image_reflection_space = 10;
TestProcess($handle, '40px reflection and 10 pixels space, into JPEG', "\$foo->image_convert = 'jpg';\n\$foo->image_reflection_height = '40px';\n\$foo->image_reflection_space = 10;");
// -----------
$handle->image_reflection_height = 60;
$handle->image_reflection_space = -40;
TestProcess($handle, '60px reflection and -40 pixels space', "\$foo->image_reflection_height = 60;\n\$foo->image_reflection_space = -40;");
// -----------
$handle->image_reflection_height = 50;
$handle->image_reflection_opacity = 100;
TestProcess($handle, '50px reflection and 100% opacity', "\$foo->image_reflection_height = 50;\n\$foo->image_reflection_opacity = 100;");
// -----------
$handle->image_reflection_height = 50;
$handle->image_reflection_opacity = 20;
TestProcess($handle, '50px reflection and 20% opacity', "\$foo->image_reflection_height = 50;\n\$foo->image_reflection_opacity = 20;");
// -----------
$handle->image_reflection_height = '50%';
$handle->image_default_color = '#000000';
TestProcess($handle, '50% reflection, black background', "\$foo->image_reflection_height = '50%';\n\$foo->image_default_color = '#000000';");
// -----------
$handle->image_convert = 'gif';
$handle->image_reflection_height = '50%';
$handle->image_default_color = '#FF00FF';
TestProcess($handle, '50% reflection, pink background, into GIF', "\$foo->image_convert = 'gif';\n\$foo->image_reflection_height = '50%';\n\$foo->image_default_color = '#000000';");
// -----------
$handle->image_watermark = "watermark.png";
TestProcess($handle, 'overlayed watermark (alpha transparent PNG)', "\$foo->image_watermark = 'watermark.png';");
// -----------
$handle->image_watermark = "watermark.png";
$handle->image_watermark_position = 'R';
TestProcess($handle, 'overlayed watermark, right position', "\$foo->image_watermark = 'watermark.png';\n\$foo->image_watermark_position = 'R;");
// -----------
$handle->image_watermark = "watermark.png";
$handle->image_watermark_x = 10;
$handle->image_watermark_y = 10;
$handle->image_greyscale = true;
TestProcess($handle, 'watermark on greyscale pic, absolute position', "\$foo->image_watermark = 'watermark.png';\n\$foo->image_watermark_x = 10;\n\$foo->image_watermark_y = 10;\n\$foo->image_greyscale = true;");
// -----------
$handle->image_watermark = "watermark.png";
$handle->image_watermark_no_zoom_in = false;
TestProcess($handle, 'watermark, automatic up-resizing activated', "\$foo->image_watermark = 'watermark.png';\n\$foo->image_watermark_no_zoom_in = false;");
// -----------
$handle->image_watermark = "watermark_large.png";
TestProcess($handle, 'large watermark automatically reduced (default)', "\$foo->image_watermark = 'watermark_large.png';");
// -----------
$handle->image_watermark = "watermark_large.png";
$handle->image_watermark_no_zoom_out = true;
TestProcess($handle, 'large watermark, automatic down-resizing deactivated', "\$foo->image_watermark = 'watermark_large.png';\n\$foo->image_watermark_no_zoom_out = true;");
// -----------
$handle->image_watermark = "watermark_large.png";
$handle->image_watermark_no_zoom_out = true;
$handle->image_watermark_position = 'TL';
TestProcess($handle, 'large watermark, down-resizing deactivated, position top-left', "\$foo->image_watermark = 'watermark_large.png';\n\$foo->image_watermark_no_zoom_out = true;\n\$foo->image_watermark_position = 'TL'");
// -----------
$handle->image_watermark = "watermark_large.png";
$handle->image_watermark_x = 20;
$handle->image_watermark_y = -20;
TestProcess($handle, 'large watermark automatically reduced, position 20 -20', "\$foo->image_watermark = 'watermark_large.png';\n\$foo->image_watermark_x = 20;\n\$foo->image_watermark_y = -20;");
// -----------
$handle->image_convert = 'jpg';
$handle->jpeg_size = 3072;
TestProcess($handle, 'desired JPEG size set to 3KB', "\$foo->image_convert = 'jpg';\n\$foo->jpeg_size = 3072;");
// -----------
$handle->image_convert = 'jpg';
$handle->jpeg_quality = 10;
TestProcess($handle, 'JPG quality set to 10%', "\$foo->image_convert = 'jpg';\n\$foo->jpeg_quality = 10;");
// -----------
$handle->image_convert = 'jpg';
$handle->jpeg_quality = 80;
TestProcess($handle, 'JPG quality set to 80%', "\$foo->image_convert = 'jpg';\n\$foo->jpeg_quality = 80;");
// -----------
$handle->image_convert = 'png';
$handle->png_compression = 0;
TestProcess($handle, 'PNG compression set to 0 (fast, large files)', "\$foo->image_convert = 'png';\n\$foo->png_compression = 0;");
// -----------
$handle->image_convert = 'png';
$handle->png_compression = 9;
TestProcess($handle, 'PNG compression set to 9 (slow, smaller files)', "\$foo->image_convert = 'png';\n\$foo->png_compression = 9;");
} else {
// if we are here, the local file failed for some reasons
echo '<b>local file error</b><br />';
echo 'Error: ' . $handle->error . '';
}
}
echo '<p class="result"><a href="index.html">do another test</a></p>';
if (isset($handle)) {
echo '<pre>';
echo($handle->log);
echo '</pre>';
}
?>
</body>
</html>