예제 #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
 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 deleteImage($imgIdDel, $removeImg)
 {
     $retStr = '';
     $imgManager = new ImageShared();
     if ($imgManager->deleteImage($imgIdDel, $removeImg)) {
         $retStr = $imgManager->getTid();
     }
     $errArr = $imgManager->getErrArr();
     if ($errArr) {
         $retStr .= 'ERROR: (' . implode('; ', $errArr) . ')';
     }
     return $retStr;
 }
 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;
 }