basedir = $basedir; } function scan_dir( $path, $scanning ) { $contents = array('dir' => array(), 'file' => array(), 'scanned' => 0, 'count' => 0); $d = opendir($this->basedir . $path); while (($file = readdir($d)) !== false) { if (in_array($file, array('.'))) { continue; } //echo "file: $file"; $type = filetype($this->basedir . $path . $file); switch ($type) { case 'dir': case 'link': $contents['dir'][] = array($file); break; default: if (!preg_match("@\.(\.|jpg|png|cr2)$@i", $file)) { continue; } $ffile = "{$this->basedir}{$path}{$file}"; $fingerprint = Image::calculateFingerprintForFile( $ffile ); $scanned = Image::fetchImageFromFingerprint( $fingerprint ); //var_dump($scanned); if ( $scanning && ( $scanned == false ) ) { $session = phPersistentObjectSession::instance(); echo "scanning $file
"; $scanned = new Image(); $scanned->fingerprint = $fingerprint; $scanned->title = ""; $scanned->rating = 1; $scanned->aperture = (float)1/4; $scanned->iso = 100; $scanned->shutterspeed=30; $scanned->focal_length=300; $scanned->flash_used=1; $scanned->time= filemtime( $ffile ); $scanned->record_modification_time = time(); $scanned->geolocation_id = 5; $scanned->photographer_id = "kake"; $session->save( $scanned ); $tmb = $this->createThumbnail( $ffile ); file_put_contents( dirname( __FILE__ ) . "/../../cache/" . $fingerprint . ".tmb.jpg", $tmb ); } $contents['file'][] = array( 'name' => $file, 'fingerprint' => $fingerprint, 'image' => $scanned, 'tmb' => $fingerprint . '.tmb.jpg' ); //array($file, $sha1, $scanned, $mime, date(DATE_RFC822, $image['date']), $image['width'], $image['height'], $image['ranking'], $kwl, $image['description']); $contents['scanned'] += $scanned; $contents['count']++; break; } } closedir($d); return $contents; } function update_dir( $path, $vars ) { //var_dump ( $vars ); foreach ( $vars['keywords'] as $fingerprint => $keywords ) { if ( $keywords ) { $keyword_array = explode( ',', $keywords ); foreach ( $keyword_array as $index => $keyword ) { echo "checking $keyword for $fingerprint
"; } } } } function createThumbnail( $file ) { //$type = mime_content_type($path); $type = 'kake'; // don't worry about mimetype for now $extension = strtolower( substr( $file, -4, 4 ) ); $raw_formats = array( '.cr2', '.nef', '.crw' ); if ( in_array( $extension, $raw_formats ) ) { $type = "image/raw"; } $rotate = ''; /* $orientation = $this->get_orientation( $file ); if ($orientation != 0) { $rotate = "-rotate $orientation "; } */ $path = $file; switch ($type) { case 'image/raw': $command = "dcraw -c -h $path > /tmp/photon.ppm"; //echo "running $command"; shell_exec( $command ); $path = "/tmp/photon.ppm"; case 'image/png': case 'image/jpeg': default: `convert -resize x96 $rotate-quality 75 '$path' '/tmp/photon.tmb.jpg'`; break; } $tmb = file_get_contents('/tmp/photon.tmb.jpg'); return $tmb; } } ?>