$filesData = simplexml_load_file("{$itemPath}/{$id}_files.xml"); } else { BRfatal("File metadata not found!"); } $imageStackInfo = findImageStack($subPrefix, $filesData); if ($imageStackInfo['imageFormat'] == 'unknown') { BRfatal('Couldn\'t find image stack'); } $imageFormat = $imageStackInfo['imageFormat']; $archiveFormat = $imageStackInfo['archiveFormat']; $imageStackFile = $itemPath . "/" . $imageStackInfo['imageStackFile']; if ("unknown" == $imageFormat) { BRfatal("Unknown image format"); } if ("unknown" == $archiveFormat) { BRfatal("Unknown archive format"); } $scanDataFile = "{$subItemPath}_scandata.xml"; $scanDataZip = "{$itemPath}/scandata.zip"; if (file_exists($scanDataFile)) { checkPrivs($scanDataFile); $scanData = simplexml_load_file($scanDataFile); } else { if (file_exists($scanDataZip)) { checkPrivs($scanDataZip); $cmd = 'unzip -p ' . escapeshellarg($scanDataZip) . ' scandata.xml'; exec($cmd, $output, $retval); if ($retval != 0) { BRFatal("Could not unzip ScanData!"); } $dump = join("\n", $output);
You should have received a copy of the GNU Affero General Public License along with BookReader. If not, see <http://www.gnu.org/licenses/>. */ require_once 'BookReaderImages.inc.php'; function BRfatal($message) { header("HTTP/1.0 404 Not Found"); header("Content-type: text/plain"); print $message; die(-1); } $allowedPages = array('title', 'cover', 'cover0', 'preview'); $allowedPattern = '#^(' . join('|', $allowedPages) . ')#'; $page = $_REQUEST['page']; if (preg_match($allowedPattern, $page)) { // Return image data $bri = new BookReaderImages(); try { $bri->serveLookupRequest($_REQUEST); } catch (Exception $e) { header("HTTP/1.0 404 Not Found"); header("Content-type: text/plain"); print "Error serving request:\n"; print " " . $e->getMessage() . "\n\n"; print "Debugging information:\n"; echo $e->getTraceAsString(); } } else { BRfatal("Bad or no page specified"); }
function getImageInfo($zipPath, $file) { global $exiftool; $fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $type = imageExtensionToType($fileExt); // We look for all the possible tags of interest then act on the // ones presumed present based on the file type $tagsToGet = ' -ImageWidth -ImageHeight -FileType' . ' -BitsPerComponent -ColorSpace' . ' -BitDepth' . ' -BitsPerSample'; // tiff $cmd = getUnarchiveCommand($zipPath, $file) . ' | ' . $exiftool . ' -S -fast' . $tagsToGet . ' -'; exec($cmd, $output); $tags = array(); foreach ($output as $line) { $keyValue = explode(": ", $line); $tags[$keyValue[0]] = $keyValue[1]; } $width = intval($tags["ImageWidth"]); $height = intval($tags["ImageHeight"]); $type = strtolower($tags["FileType"]); switch ($type) { case "jp2": $bits = intval($tags["BitsPerComponent"]); break; case "tiff": $bits = intval($tags["BitsPerSample"]); break; case "jpeg": $bits = 8; break; case "png": $bits = intval($tags["BitDepth"]); break; default: BRfatal("Unsupported image type"); break; } $retval = array('width' => $width, 'height' => $height, 'bits' => $bits, 'type' => $type); return $retval; }