示例#1
0
 public function buildThumbnailImages($collid = 0)
 {
     ini_set('memory_limit', '512M');
     $imgManager = new ImageShared();
     $imgManager->setTargetPath('misc');
     $sql = 'SELECT ti.imgid, ti.url, ti.originalurl ' . 'FROM images ti ';
     if ($collid) {
         $sql .= 'INNER JOIN omoccurrences o ON ti.occid = o.occid ';
     }
     $sql .= 'WHERE (ti.thumbnailurl IS NULL OR ti.thumbnailurl = "") ';
     if ($collid) {
         $sql .= 'AND (o.collid = ' . $collid . ') ';
     }
     //$sql .= 'LIMIT 100';
     //echo $sql; exit;
     $result = $this->conn->query($sql);
     while ($row = $result->fetch_object()) {
         $status = true;
         $webIsEmpty = false;
         $imgId = $row->imgid;
         if ($this->verbose) {
             echo '<li>Building thumbnail: <a href="../imgdetails.php?imgid=' . $imgId . '" target="_blank">' . $imgId . '</a>... ';
         }
         $imgUrl = trim($row->url);
         if ((!$imgUrl || $imgUrl == 'empty') && $row->originalurl) {
             $imgUrl = trim($row->originalurl);
             $webIsEmpty = true;
         }
         if ($imgManager->parseUrl($imgUrl)) {
             //Create thumbnail
             $imgTnUrl = '';
             if ($imgManager->createNewImage('_tn', $imgManager->getTnPixWidth(), 70)) {
                 $imgTnUrl = $imgManager->getUrlBase() . $imgManager->getImgName() . '_tn.jpg';
             } else {
                 $this->errorStr = 'ERROR building thumbnail: ' . implode('; ', $imgManager->getErrArr());
                 $status = false;
             }
             if ($status && $imgTnUrl && $imgManager->uriExists($imgTnUrl)) {
                 $webFullUrl = '';
                 $lgFullUrl = '';
                 //If web image is too large, transfer to large image and create new web image
                 list($sourceWidth, $sourceHeight) = getimagesize($imgManager->getSourcePath());
                 if (!$webIsEmpty && !$row->originalurl) {
                     $fileSize = $imgManager->getSourceFileSize();
                     if ($fileSize > $imgManager->getWebFileSizeLimit() || $sourceWidth > $imgManager->getWebPixWidth() * 1.2) {
                         $lgFullUrl = $imgManager->getSourcePath();
                         $webIsEmpty = true;
                     }
                 }
                 if ($webIsEmpty) {
                     if ($sourceWidth && $sourceWidth < $imgManager->getWebPixWidth()) {
                         if (copy($imgManager->getSourcePath(), $imgManager->getTargetPath() . $imgManager->getImgName() . '_web' . $imgManager->getImgExt())) {
                             $webFullUrl = $imgManager->getUrlBase() . $imgManager->getImgName() . '_web' . $imgManager->getImgExt();
                         }
                     }
                     if (!$webFullUrl) {
                         if ($imgManager->createNewImage('_web', $imgManager->getWebPixWidth())) {
                             $webFullUrl = $imgManager->getUrlBase() . $imgManager->getImgName() . '_web.jpg';
                         }
                     }
                 }
                 $sql = 'UPDATE images ti SET ti.thumbnailurl = "' . $imgTnUrl . '" ';
                 if ($webFullUrl) {
                     $sql .= ',url = "' . $webFullUrl . '" ';
                 }
                 if ($lgFullUrl) {
                     $sql .= ',originalurl = "' . $lgFullUrl . '" ';
                 }
                 $sql .= "WHERE ti.imgid = " . $imgId;
                 //echo $sql;
                 if (!$this->conn->query($sql)) {
                     $status = false;
                     $this->errorStr = 'ERROR: thumbnail created but failed to update database: ' . $this->conn->error;
                 }
             }
             $imgManager->reset();
         } else {
             $status = false;
             $this->errorStr = 'ERROR: unable to parse source image (' . $imgUrl . ')';
         }
         ob_flush();
         flush();
         if ($this->verbose) {
             if ($status) {
                 echo 'Done!</li>';
             } else {
                 echo $this->errorStr . '</li>';
             }
         }
     }
     $result->free();
 }
 public function addImage($postArr)
 {
     $status = true;
     $imgManager = new ImageShared();
     //Set target path
     $subTargetPath = $this->collMap['institutioncode'];
     if ($this->collMap['collectioncode']) {
         $subTargetPath .= '_' . $this->collMap['collectioncode'];
     }
     $imgManager->setTargetPath($subTargetPath);
     //Import large image or not
     if (array_key_exists('nolgimage', $postArr) && $postArr['nolgimage'] == 1) {
         $imgManager->setMapLargeImg(false);
     } else {
         $imgManager->setMapLargeImg(true);
     }
     //Set image metadata variables
     if (array_key_exists('caption', $postArr)) {
         $imgManager->setCaption($postArr['caption']);
     }
     if (array_key_exists('photographeruid', $postArr)) {
         $imgManager->setPhotographerUid($postArr['photographeruid']);
     }
     if (array_key_exists('photographer', $postArr)) {
         $imgManager->setPhotographer($postArr['photographer']);
     }
     if (array_key_exists('sourceurl', $postArr)) {
         $imgManager->setSourceUrl($postArr['sourceurl']);
     }
     if (array_key_exists('copyright', $postArr)) {
         $imgManager->setCopyright($postArr['copyright']);
     }
     if (array_key_exists("notes", $postArr)) {
         $imgManager->setNotes($postArr['notes']);
     }
     if (array_key_exists("sortsequence", $postArr)) {
         $imgManager->setSortSeq($postArr['sortsequence']);
     }
     $sourceImgUri = $postArr['imgurl'];
     if ($sourceImgUri) {
         //Source image is a URI supplied by user
         if (array_key_exists('copytoserver', $postArr) && $postArr['copytoserver']) {
             if (!$imgManager->copyImageFromUrl($sourceImgUri)) {
                 $status = false;
             }
         } else {
             $imgManager->parseUrl($sourceImgUri);
         }
     } else {
         //Image is a file upload
         if (!$imgManager->uploadImage()) {
             $status = false;
         }
     }
     $imgManager->setOccid($this->occid);
     if ($imgManager->processImage()) {
         $this->activeImgId = $imgManager->getActiveImgId();
     }
     //Load tags
     $status = $imgManager->insertImageTags($postArr);
     //Get errors and warnings
     if ($imgManager->getErrArr()) {
         $this->errorStr = implode('<br/>', $imgManager->getErrArr());
     }
     return $status;
 }
 public function loadImage($postArr)
 {
     $status = true;
     $imgManager = new ImageShared();
     $imgPath = $postArr["filepath"];
     $imgManager->setTid($this->tid);
     $imgManager->setCaption($postArr['caption']);
     $imgManager->setPhotographer($postArr['photographer']);
     $imgManager->setPhotographerUid($postArr['photographeruid']);
     $imgManager->setSourceUrl($postArr['sourceurl']);
     $imgManager->setCopyright($postArr['copyright']);
     $imgManager->setOwner($postArr['owner']);
     $imgManager->setLocality($postArr['locality']);
     $imgManager->setOccid($postArr['occid']);
     $imgManager->setNotes($postArr['notes']);
     $imgManager->setSortSeq($postArr['sortsequence']);
     $imgManager->setTargetPath($this->family . '/' . date('Ym') . '/');
     if ($imgPath) {
         $imgManager->setMapLargeImg(true);
         $importUrl = array_key_exists('importurl', $postArr) && $postArr['importurl'] == 1 ? true : false;
         if ($importUrl) {
             $imgManager->copyImageFromUrl($imgPath);
         } else {
             $imgManager->parseUrl($imgPath);
         }
     } else {
         if (array_key_exists('createlargeimg', $postArr) && $postArr['createlargeimg'] == 1) {
             $imgManager->setMapLargeImg(true);
         } else {
             $imgManager->setMapLargeImg(false);
         }
         if (!$imgManager->uploadImage()) {
             //echo implode('; ',$imgManager->getErrArr());
         }
     }
     $imgManager->processImage();
     if ($imgManager->getErrArr()) {
         $this->errorStr = implode('<br/>', $imgManager->getErrArr());
     }
     return $status;
 }
示例#4
0
 private function buildImages($targetPath, $collid = 0)
 {
     ini_set('memory_limit', '512M');
     $imgManager = new ImageShared();
     $sql = '';
     if ($collid) {
         $sql = 'SELECT i.imgid, i.url, i.originalurl, i.thumbnailurl, o.catalognumber ' . 'FROM images i INNER JOIN omoccurrences o ON i.occid = o.occid ' . 'WHERE (o.collid = ' . $collid . ') ';
     } else {
         $sql = 'SELECT i.imgid, i.url, i.originalurl, i.thumbnailurl ' . 'FROM images i ' . 'WHERE (i.occid IS NULL) ';
     }
     $sql .= 'AND ((i.thumbnailurl IS NULL) OR (i.thumbnailurl = "") OR (i.thumbnailurl = "bad url") OR (i.thumbnailurl LIKE "processing%") OR (i.url LIKE "processing%") OR (i.url = "empty")) ' . 'ORDER BY RAND()';
     //echo $sql; exit;
     $result = $this->conn->query($sql);
     if ($this->verbose) {
         echo '<ol style="margin-left:15px;">';
     }
     while ($row = $result->fetch_object()) {
         $status = true;
         $webIsEmpty = false;
         $imgId = $row->imgid;
         if ($this->verbose) {
             echo '<li>Building thumbnail: <a href="../imgdetails.php?imgid=' . $imgId . '" target="_blank">' . $imgId . '</a>...</li> ';
             ob_flush();
             flush();
         }
         $this->conn->autocommit(false);
         //Tag for updating; needed to ensure two parallel processes are not processing the same image
         $testSql = 'SELECT thumbnailurl, url FROM images WHERE (imgid = ' . $imgId . ') FOR UPDATE ';
         $textRS = $this->conn->query($testSql);
         if ($testR = $textRS->fetch_object()) {
             if (!$testR->thumbnailurl || substr($testR->thumbnailurl, 0, 10) == 'processing' && $testR->thumbnailurl != 'processing ' . date('Y-m-d')) {
                 $tagSql = 'UPDATE images SET thumbnailurl = "processing ' . date('Y-m-d') . '" ' . 'WHERE (imgid = ' . $imgId . ')';
                 $this->conn->query($tagSql);
             } elseif ($testR->url == 'empty' || substr($testR->url, 0, 10) == 'processing' && $testR->url != 'processing ' . date('Y-m-d')) {
                 $tagSql = 'UPDATE images SET url = "processing ' . date('Y-m-d') . '" ' . 'WHERE (imgid = ' . $imgId . ')';
                 $this->conn->query($tagSql);
             } else {
                 //Records already processed by a parallel running process, thus go to next record
                 if ($this->verbose) {
                     echo '<div style="margin-left:30px">Already being handled by a parallel running processs</div>';
                 }
                 $textRS->free();
                 $this->conn->commit();
                 $this->conn->autocommit(true);
                 continue;
             }
         }
         $textRS->free();
         $this->conn->commit();
         $this->conn->autocommit(true);
         //Build target path
         $finalPath = $targetPath;
         if ($collid) {
             $catNum = $row->catalognumber;
             if ($catNum) {
                 $catNum = str_replace(array('/', '\\', ' '), '', $catNum);
                 if (preg_match('/^(\\D{0,8}\\d{4,})/', $catNum, $m)) {
                     $catPath = substr($m[1], 0, -3);
                     if (is_numeric($catPath) && strlen($catPath) < 5) {
                         $catPath = str_pad($catPath, 5, "0", STR_PAD_LEFT);
                     }
                     $finalPath .= $catPath . '/';
                 } else {
                     $finalPath .= '00000/';
                 }
             } else {
                 $finalPath .= date('Ym') . '/';
             }
         }
         $imgManager->setTargetPath($finalPath);
         $imgUrl = trim($row->url);
         if ((!$imgUrl || $imgUrl == 'empty') && $row->originalurl) {
             $imgUrl = trim($row->originalurl);
             $webIsEmpty = true;
         }
         if ($imgManager->parseUrl($imgUrl)) {
             //Create thumbnail
             $imgTnUrl = '';
             if (!$row->thumbnailurl || substr($testR->thumbnailurl, 0, 10) == 'processing') {
                 if ($imgManager->createNewImage('_tn', $imgManager->getTnPixWidth(), 70)) {
                     $imgTnUrl = $imgManager->getUrlBase() . $imgManager->getImgName() . '_tn.jpg';
                 } else {
                     $this->errorStr = 'ERROR building thumbnail: ' . $imgManager->getErrStr();
                     $errSql = 'UPDATE images SET thumbnailurl = "bad url" WHERE thumbnailurl IS NULL AND imgid = ' . $imgId;
                     $this->conn->query($errSql);
                     $status = false;
                 }
             } else {
                 $imgTnUrl = $row->thumbnailurl;
             }
             if ($status && $imgTnUrl && $imgManager->uriExists($imgTnUrl)) {
                 $webFullUrl = '';
                 $lgFullUrl = '';
                 //If web image is too large, transfer to large image and create new web image
                 list($sourceWidth, $sourceHeight) = getimagesize($imgManager->getSourcePath());
                 if (!$webIsEmpty && !$row->originalurl) {
                     $fileSize = $imgManager->getSourceFileSize();
                     if ($fileSize > $imgManager->getWebFileSizeLimit() || $sourceWidth > $imgManager->getWebPixWidth() * 1.2) {
                         $lgFullUrl = $imgManager->getSourcePath();
                         $webIsEmpty = true;
                     }
                 }
                 if ($webIsEmpty) {
                     if ($sourceWidth && $sourceWidth < $imgManager->getWebPixWidth()) {
                         if (copy($imgManager->getSourcePath(), $imgManager->getTargetPath() . $imgManager->getImgName() . '_web' . $imgManager->getImgExt())) {
                             $webFullUrl = $imgManager->getUrlBase() . $imgManager->getImgName() . '_web' . $imgManager->getImgExt();
                         }
                     }
                     if (!$webFullUrl) {
                         if ($imgManager->createNewImage('_web', $imgManager->getWebPixWidth())) {
                             $webFullUrl = $imgManager->getUrlBase() . $imgManager->getImgName() . '_web.jpg';
                         }
                     }
                 }
                 $sql = 'UPDATE images ti SET ti.thumbnailurl = "' . $imgTnUrl . '" ';
                 if ($webFullUrl) {
                     $sql .= ',url = "' . $webFullUrl . '" ';
                 }
                 if ($lgFullUrl) {
                     $sql .= ',originalurl = "' . $lgFullUrl . '" ';
                 }
                 $sql .= "WHERE ti.imgid = " . $imgId;
                 //echo $sql;
                 if (!$this->conn->query($sql)) {
                     $this->errorStr = 'ERROR: thumbnail created but failed to update database: ' . $this->conn->error;
                     if ($this->verbose) {
                         echo '<div style="margin-left:30px">' . $this->errorStr . '</div>';
                     }
                     $status = false;
                 }
             }
             $imgManager->reset();
         } else {
             $this->errorStr = 'ERROR: unable to parse source image (' . $imgUrl . ')';
             if ($this->verbose) {
                 echo '<div style="margin-left:30px">' . $this->errorStr . '</div>';
             }
             $status = false;
         }
         if ($this->verbose && !$status) {
             echo $this->errorStr . '</li>';
         }
         ob_flush();
         flush();
     }
     $result->free();
     if ($this->verbose) {
         echo '</ol>';
     }
 }
 public function addImage($postArr)
 {
     $status = true;
     $imgManager = new ImageShared();
     //Set target path
     $subTargetPath = $this->collMap['institutioncode'];
     if ($this->collMap['collectioncode']) {
         $subTargetPath .= '_' . $this->collMap['collectioncode'];
     }
     $subTargetPath .= '/';
     if (!$this->occurrenceMap) {
         $this->setOccurArr();
     }
     $catNum = $this->occurrenceMap[$this->occid]['catalognumber'];
     if ($catNum) {
         $catNum = str_replace(array('/', '\\', ' '), '', $catNum);
         if (preg_match('/^(\\D{0,8}\\d{4,})/', $catNum, $m)) {
             $catPath = substr($m[1], 0, -3);
             if (is_numeric($catPath) && strlen($catPath) < 5) {
                 $catPath = str_pad($catPath, 5, "0", STR_PAD_LEFT);
             }
             $subTargetPath .= $catPath . '/';
         } else {
             $subTargetPath .= '00000/';
         }
     } else {
         $subTargetPath .= date('Ym') . '/';
     }
     $imgManager->setTargetPath($subTargetPath);
     //Import large image or not
     if (array_key_exists('nolgimage', $postArr) && $postArr['nolgimage'] == 1) {
         $imgManager->setMapLargeImg(false);
     } else {
         $imgManager->setMapLargeImg(true);
     }
     //Set image metadata variables
     if (array_key_exists('caption', $postArr)) {
         $imgManager->setCaption($postArr['caption']);
     }
     if (array_key_exists('photographeruid', $postArr)) {
         $imgManager->setPhotographerUid($postArr['photographeruid']);
     }
     if (array_key_exists('photographer', $postArr)) {
         $imgManager->setPhotographer($postArr['photographer']);
     }
     if (array_key_exists('sourceurl', $postArr)) {
         $imgManager->setSourceUrl($postArr['sourceurl']);
     }
     if (array_key_exists('copyright', $postArr)) {
         $imgManager->setCopyright($postArr['copyright']);
     }
     if (array_key_exists("notes", $postArr)) {
         $imgManager->setNotes($postArr['notes']);
     }
     if (array_key_exists("sortsequence", $postArr)) {
         $imgManager->setSortSeq($postArr['sortsequence']);
     }
     $sourceImgUri = $postArr['imgurl'];
     if ($sourceImgUri) {
         //Source image is a URI supplied by user
         if (array_key_exists('copytoserver', $postArr) && $postArr['copytoserver']) {
             if (!$imgManager->copyImageFromUrl($sourceImgUri)) {
                 $status = false;
             }
         } else {
             $imgManager->parseUrl($sourceImgUri);
         }
     } else {
         //Image is a file upload
         if (!$imgManager->uploadImage()) {
             $status = false;
         }
     }
     $imgManager->setOccid($this->occid);
     if (isset($this->occurrenceMap[$this->occid]['tidinterpreted'])) {
         $imgManager->setTid($this->occurrenceMap[$this->occid]['tidinterpreted']);
     }
     if ($imgManager->processImage()) {
         $this->activeImgId = $imgManager->getActiveImgId();
     }
     //Load tags
     $status = $imgManager->insertImageTags($postArr);
     //Get errors and warnings
     if ($imgManager->getErrArr()) {
         $this->errorStr = implode('<br/>', $imgManager->getErrArr());
     }
     return $status;
 }
 public function addImages($postArr, $newOccId, $tid)
 {
     $status = true;
     $imgManager = new ImageShared();
     //Set target path
     $subTargetPath = $this->collMap['institutioncode'];
     if ($this->collMap['collectioncode']) {
         $subTargetPath .= '_' . $this->collMap['collectioncode'];
     }
     for ($i = 1; $i <= 3; $i++) {
         //Set parameters
         $imgManager->setTargetPath($subTargetPath . '/' . date('Ym') . '/');
         $imgManager->setMapLargeImg(false);
         //Do not import large image, at least for now
         $imgManager->setPhotographerUid($GLOBALS['SYMB_UID']);
         $imgManager->setSortSeq(40);
         $imgManager->setOccid($newOccId);
         $imgManager->setTid($tid);
         $imgFileName = 'imgfile' . $i;
         if (!array_key_exists($imgFileName, $_FILES) || !$_FILES[$imgFileName]['name']) {
             break;
         }
         //Set image metadata variables
         if (isset($postArr['caption' . $i])) {
             $imgManager->setCaption($postArr['caption' . $i]);
         }
         if (isset($postArr['notes' . $i])) {
             $imgManager->setNotes($postArr['notes' . $i]);
         }
         //Image is a file upload
         if ($imgManager->uploadImage($imgFileName)) {
             $status = $imgManager->processImage();
         } else {
             $status = false;
         }
         if (!$status) {
             //Get errors and warnings
             if ($errArr = $imgManager->getErrArr()) {
                 foreach ($errArr as $errStr) {
                     $this->errArr[] = $errStr;
                 }
             }
         }
         $imgManager->reset();
     }
     return $status;
 }