Mercurial > hg > fapweb
comparison faptool.php @ 984:03b245ef3a47
Various fixes to previews generation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 29 Nov 2014 16:04:21 +0200 |
parents | 1e347288712d |
children | 31dc100c78d4 |
comparison
equal
deleted
inserted
replaced
983:1e347288712d | 984:03b245ef3a47 |
---|---|
8 require_once "mconfig.inc.php"; | 8 require_once "mconfig.inc.php"; |
9 require_once "msite.inc.php"; | 9 require_once "msite.inc.php"; |
10 | 10 |
11 | 11 |
12 | 12 |
13 function wtConvertImage($inFilename, $inFileType, $outFilename, $setDim, $setFormat, $setQuality, $thumb) | 13 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv) |
14 { | 14 { |
15 global $setPreviewPath; | 15 global $setPreviewPath; |
16 $isTemp = FALSE; | 16 $isTemp = FALSE; |
17 | 17 |
18 if ($inFileType == "gfx") | 18 if ($useGfxConv) |
19 { | 19 { |
20 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit | 20 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit |
21 $tmpFilename = tempnam($setPreviewPath, "tmp"); | 21 $tmpFilename = tempnam($setPreviewPath, "tmp"); |
22 $isTemp = TRUE; | 22 $isTemp = TRUE; |
23 if (wtExec( | 23 if (wtExec( |
33 } | 33 } |
34 } | 34 } |
35 else | 35 else |
36 $tmpFilename = $inFilename; | 36 $tmpFilename = $inFilename; |
37 | 37 |
38 // convert -resize 640x480 -background black -gravity center -extent 640x480 | |
39 // -unsharp "0x0.75+0.75+0.008" lol.lbm -quality 95 test.jpg | |
40 | |
41 // Create conversion entity | 38 // Create conversion entity |
42 $img = new Imagick($tmpFilename); | 39 $img = new Imagick($tmpFilename); |
43 if ($img === false) | 40 if ($img === false) |
44 { | 41 { |
45 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n"; | 42 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n"; |
46 return FALSE; | 43 return FALSE; |
47 } | 44 } |
48 | 45 |
49 if ($setDim !== FALSE) | 46 if ($outDim !== FALSE) |
50 { | 47 { |
51 if (($outDim = stGetSetting($setDim)) === FALSE || | |
52 ($outFormat = stGetSetting($setFormat)) === FALSE || | |
53 ($outQuality = stGetSetting($setQuality)) === FALSE) | |
54 { | |
55 die("Missing one of res/format/quality settings for '".$outFilename."'\n"); | |
56 } | |
57 | |
58 // Get dimensions, setup background | 48 // Get dimensions, setup background |
59 $dim = $img->getImageGeometry(); | 49 $dim = $img->getImageGeometry(); |
60 // $img->setBackgroundColor(imagick::COLOR_BLACK); | 50 // $img->setBackgroundColor(imagick::COLOR_BLACK); |
61 $img->setGravity(imagick::GRAVITY_CENTER); | 51 $img->setGravity(imagick::GRAVITY_CENTER); |
62 | 52 |
82 $img->setCompressionQuality($outQuality); | 72 $img->setCompressionQuality($outQuality); |
83 | 73 |
84 $img->stripImage(); | 74 $img->stripImage(); |
85 $img->writeImage($outFilename); | 75 $img->writeImage($outFilename); |
86 $img->removeImage(); | 76 $img->removeImage(); |
77 return TRUE; | |
87 } | 78 } |
88 | 79 |
89 | 80 |
90 function wtRenderSample($inFilename, $outFilename) | 81 function wtRenderSample($inFilename, $outFilename) |
91 { | 82 { |
109 { | 100 { |
110 $sfreq = intval(stGetSetting("sampleFreq")); | 101 $sfreq = intval(stGetSetting("sampleFreq")); |
111 $sduration = intval(stGetSetting("sampleDuration")); | 102 $sduration = intval(stGetSetting("sampleDuration")); |
112 $schannels = intval(stGetSetting("sampleChannels")); | 103 $schannels = intval(stGetSetting("sampleChannels")); |
113 | 104 |
105 $optStr = ""; | |
114 foreach ($outOpts as $okey => $oval) | 106 foreach ($outOpts as $okey => $oval) |
115 $optStr .= $okey." ".$oval." "; | 107 $optStr .= $okey." ".$oval." "; |
116 | 108 |
117 return wtExec( | 109 return wtExec( |
118 "/usr/local/bin/avconv", | 110 "/usr/local/bin/avconv", |
119 "-y -t ".intval($sduration)." ". | 111 "-y -v 1 -t ".intval($sduration)." ". |
120 "-i ".escapeshellarg($inFilename). | 112 "-i ".escapeshellarg($inFilename). |
121 " ".$optStr." -ac ".$schannels. | 113 " ".$optStr." -ac ".$schannels. |
122 " -map_metadata -1 ". | 114 " -map_metadata -1 ". |
123 escapeshellarg($outFilename)); | 115 escapeshellarg($outFilename)); |
124 } | 116 } |
155 break; | 147 break; |
156 | 148 |
157 case EFILE_IMAGE: | 149 case EFILE_IMAGE: |
158 $res = wtConvertImage( | 150 $res = wtConvertImage( |
159 $inFilename, | 151 $inFilename, |
160 $edata["mime"], | |
161 $outFilename, | 152 $outFilename, |
162 FALSE, "PNG", 9, FALSE); | 153 FALSE, "PNG", 9, |
154 FALSE, ($edata["mime"] == "gfx")); | |
163 break; | 155 break; |
164 } | 156 } |
165 | 157 |
166 return $res; | 158 return $res; |
167 } | 159 } |
200 | 192 |
201 // Create temporary directory | 193 // Create temporary directory |
202 wtPurgeDir($path); | 194 wtPurgeDir($path); |
203 wtMakeDir($path, 0700); | 195 wtMakeDir($path, 0700); |
204 | 196 |
197 $cwd = getcwd(); | |
205 if (!is_dir($path) || chdir($path) === false) | 198 if (!is_dir($path) || chdir($path) === false) |
206 { | 199 { |
207 echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n"; | 200 echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n"; |
208 return FALSE; | 201 return FALSE; |
209 } | 202 } |
210 | 203 |
211 // Unpack archive | 204 // Unpack archive |
212 return wtExec($exe, $args); | 205 $ret = wtExec($exe, $args); |
206 | |
207 chdir($cwd); | |
208 return $ret; | |
213 } | 209 } |
214 | 210 |
215 | 211 |
216 function wtNiceName($compo, $entry, $efile = FALSE) | 212 function wtNiceName($compo, $entry, $efile = FALSE) |
217 { | 213 { |
303 while (($dentry = readdir($dir)) !== false) | 299 while (($dentry = readdir($dir)) !== false) |
304 { | 300 { |
305 $fname = $path."/".$dentry; | 301 $fname = $path."/".$dentry; |
306 // check file type against entry's preview_type | 302 // check file type against entry's preview_type |
307 // if match, render / convert / cp to as source and exit loop. | 303 // if match, render / convert / cp to as source and exit loop. |
308 if (is_file($fname) && | 304 if ($dentry != "." && $dentry != "..") |
309 ($mdata = stProbeFileInfo($fname, TRUE)) !== false && | 305 { |
306 if (is_dir($fname)) | |
307 echo "XXX: ".$dentry." :: ".$fname."\n"; | |
308 else | |
309 if (is_file($fname) && | |
310 ($mdata = stProbeFileInfo($fname, TRUE)) !== false && | |
310 ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename, $force)) === true) | 311 ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename, $force)) === true) |
311 break; | 312 break; |
313 } | |
312 } | 314 } |
313 | 315 |
314 // Cleanup | 316 // Cleanup |
315 closedir($dir); | 317 closedir($dir); |
316 wtPurgeDir($path); | 318 wtPurgeDir($path); |
365 break; | 367 break; |
366 | 368 |
367 case EFILE_IMAGE: | 369 case EFILE_IMAGE: |
368 wtConvertImage( | 370 wtConvertImage( |
369 $inFilename, | 371 $inFilename, |
370 "png", | |
371 $pdata["files"]["image"]["file"], | 372 $pdata["files"]["image"]["file"], |
372 "previewImageSize", "previewImageType", | 373 stGetSetting("previewImageSize"), |
373 "previewImageQuality", FALSE); | 374 stGetSetting("previewImageType"), |
375 stGetSetting("previewImageQuality"), | |
376 FALSE, FALSE); | |
374 | 377 |
375 wtConvertImage( | 378 wtConvertImage( |
376 $inFilename, | 379 $inFilename, |
377 "png", | |
378 $pdata["files"]["thumb"]["file"], | 380 $pdata["files"]["thumb"]["file"], |
379 "previewThumbSize", "previewThumbType", | 381 stGetSetting("previewThumbSize"), |
380 "previewThumbQuality", TRUE); | 382 stGetSetting("previewThumbType"), |
383 stGetSetting("previewThumbQuality"), | |
384 TRUE, FALSE); | |
381 break; | 385 break; |
382 } | 386 } |
383 | 387 |
384 return TRUE; | 388 return TRUE; |
385 } | 389 } |
444 // | 448 // |
445 // Misc helper functions | 449 // Misc helper functions |
446 // | 450 // |
447 function wtExec($exe, $args, $expect = 0) | 451 function wtExec($exe, $args, $expect = 0) |
448 { | 452 { |
449 echo "EXEC: ".$exe." ".$args."\n"; | 453 echo "EXEC: ".$exe." @ ".$args."\n"; |
450 exec(escapeshellcmd($exe)." ".$args, $output, $code); | 454 exec(escapeshellcmd($exe)." ".$args, $output, $code); |
451 if ($code !== $expect) | 455 if ($code !== $expect) |
452 { | 456 { |
453 echo | 457 echo |
454 "ERROR: Executing ".$exe.": ".$code."\n".$args."\n". | 458 "ERROR: Executing ".$exe.": ".$code."\n".$args."\n". |