Ik heb een PHP-script dat thumbnails maakt. Alles werkt perfect, op één ding na. Ik wil graag voordat het script begint met het maken van de thumbnails dat er een regel op het scherm (client, browser) verschijnt in de zin van: 'Bezig met verwerken...'.
Dit krijg ik niet voor elkaar. Pas nadat het script helemaal klaar is, vercshijnt er iets in de browser. Hoe kan ik dit veranderen? Dit is mijn script:
Dit krijg ik niet voor elkaar. Pas nadat het script helemaal klaar is, vercshijnt er iets in de browser. Hoe kan ik dit veranderen? Dit is mijn script:
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
| echo("<html><head></head><body>Bezig met maken van thumbnails..."); $gd2=checkgd(); $pics=directory("pics","jpg,JPG,JPEG,jpeg,png,PNG"); $pics=ditchtn($pics,"tn_"); if ($pics[0]!=""){ foreach ($pics as $p){ echo("pics/".$p); createthumb("pics/".$p,"thumbs/tn_".$p,150,150); } } echo("Klaar...</body></html>"); /* Function checkgd() checks the version of gd, and returns "yes" when it's higher than 2 */ function checkgd(){ $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2'){$gd2="yes";} return $gd2; } /* Function ditchtn($arr,$thumbname) filters out thumbnails */ function ditchtn($arr,$thumbname){ foreach ($arr as $item){ if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;} } return $tmparr; } /* Function createthumb($name,$filename,$new_w,$new_h) creates a resized image variables: $name Original filename $filename Filename of the resized image $new_w width of resized image $new_h height of resized image */ function createthumb($name,$filename,$new_w,$new_h){ global $gd2; $system=explode(".",$name); if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2==""){ $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); }else{ $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])){ imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } /* Function directory($directory,$filters) reads the content of $directory, takes the files that apply to $filter and returns an array of the filenames. You can specify which files to read, for example $files = directory(".","jpg,gif"); gets all jpg and gif files in this directory. $files = directory(".","all"); gets all files. */ function directory($dir,$filters){ $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} if ($filters != "all"){ $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0;$f<sizeof($filters);$f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } |