git.cweiske.de
/
surrogator.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8f42911
)
add logging
author
Christian Weiske
<cweiske@cweiske.de>
Thu, 16 Aug 2012 18:50:58 +0000
(20:50 +0200)
committer
Christian Weiske
<cweiske@cweiske.de>
Thu, 16 Aug 2012 18:50:58 +0000
(20:50 +0200)
surrogator.php
patch
|
blob
|
history
diff --git
a/surrogator.php
b/surrogator.php
index e48190e2e71009fc5427fab4bf476c6e8ed067d1..b9f724d05446bca7a7fee401775b68ef7b5d5e2f 100644
(file)
--- a/
surrogator.php
+++ b/
surrogator.php
@@
-1,18
+1,36
@@
<?php
<?php
+namespace surrogator;
require __DIR__ . '/data/surrogator.config.php';
require __DIR__ . '/data/surrogator.config.php';
+if (!isset($rawDir)) {
+ logErr('$rawDir not set');
+}
+if (!isset($varDir)) {
+ logErr('$varDir not set');
+}
+if (!isset($sizes)) {
+ logErr('$sizes not set');
+}
+if (!isset($maxSize)) {
+ logErr('$maxSize not set');
+}
+
+
if (!is_dir($varDir . '/square')) {
if (!is_dir($varDir . '/square')) {
+ log('Creating square dir: ' . $varDir . '/square');
mkdir($varDir . '/square', 0755, true);
}
mkdir($varDir . '/square', 0755, true);
}
+log('sizes: ' . implode(', ', $sizes));
foreach ($sizes as $size) {
if (!is_dir($varDir . '/' . $size)) {
foreach ($sizes as $size) {
if (!is_dir($varDir . '/' . $size)) {
+ log('Creating size dir: ' . $varDir . '/' . $size);
mkdir($varDir . '/' . $size, 0755);
}
}
mkdir($varDir . '/' . $size, 0755);
}
}
-$dir = new RegexIterator(
- new DirectoryIterator($rawDir),
- '#^.+
@.+
\.(png|jpg)$#'
+$dir = new
\
RegexIterator(
+ new
\
DirectoryIterator($rawDir),
+ '#^.+\.(png|jpg)$#'
);
foreach ($dir as $fileInfo) {
$origPath = $fileInfo->getPathname();
);
foreach ($dir as $fileInfo) {
$origPath = $fileInfo->getPathname();
@@
-21,7
+39,9
@@
foreach ($dir as $fileInfo) {
$squarePath = $varDir . '/square/'
. substr($fileName, 0, -strlen($ext)) . 'png';
$squarePath = $varDir . '/square/'
. substr($fileName, 0, -strlen($ext)) . 'png';
+ log('processing ' . $fileName);
if (image_uptodate($origPath, $squarePath)) {
if (image_uptodate($origPath, $squarePath)) {
+ log(' image up to date');
continue;
}
continue;
}
@@
-29,8
+49,15
@@
foreach ($dir as $fileInfo) {
continue;
}
continue;
}
- list($md5, $sha256) = getHashes($fileName);
+ if ($fileName == 'default.png') {
+ $md5 = $sha256 = 'default';
+ } else {
+ list($md5, $sha256) = getHashes($fileName);
+ }
+ log(' Creating sizes for ' . $fileName);
+ log(' md5: ' . $md5);
+ log(' sha256: ' . $sha256);
$imgSquare = imagecreatefrompng($squarePath);
foreach ($sizes as $size) {
$sizePathMd5 = $varDir . '/' . $size . '/' . $md5 . '.png';
$imgSquare = imagecreatefrompng($squarePath);
foreach ($sizes as $size) {
$sizePathMd5 = $varDir . '/' . $size . '/' . $md5 . '.png';
@@
-80,10
+107,7
@@
function createSquare($origPath, $ext, $targetPath, $maxSize)
}
if ($imgOrig === false) {
}
if ($imgOrig === false) {
- file_put_contents(
- 'php://stderr',
- 'Error loading image file: ' . $origPath
- );
+ logErr('Error loading image file: ' . $origPath);
return false;
}
return false;
}
@@
-135,4
+159,14
@@
function image_uptodate($sourcePath, $targetPath)
return true;
}
return true;
}
+function log($msg)
+{
+ echo $msg . "\n";
+}
+
+function logErr($msg)
+{
+ file_put_contents('php://stderr', $msg . "\n");
+}
+
?>
?>