예제 #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();
 }
예제 #2
0
 private function testUrls($sql)
 {
     $status = true;
     $badUrlArr = array();
     if (!$sql) {
         $this->errorStr = 'SQL string is NULL';
         return false;
     }
     $imgManager = new ImageShared();
     $rs = $this->conn->query($sql);
     if ($rs) {
         while ($r = $rs->fetch_object()) {
             if (!$imgManager->uriExists($r->url)) {
                 $badUrlArr[$r->imgid]['url'] = $r->url;
             }
             if (!$imgManager->uriExists($r->thumbnailurl)) {
                 $badUrlArr[$r->imgid]['tn'] = $r->thumbnailurl;
             }
             if (!$imgManager->uriExists($r->originalurl)) {
                 $badUrlArr[$r->imgid]['lg'] = $r->originalurl;
             }
         }
         $rs->free();
     } else {
         $this->errorStr = 'Issue with connection or SQL: ' . $sql;
         return false;
     }
     //Output results (needs to be extended)
     foreach ($badUrlArr as $imgid => $badUrls) {
         echo $imgid . ', ';
         echo (isset($badUrls['url']) ? $badUrls['url'] : '') . ',';
         echo (isset($badUrls['tn']) ? $badUrls['tn'] : '') . ',';
         echo (isset($badUrls['lg']) ? $badUrls['lg'] : '') . ',';
         echo '<br/>';
     }
     return $status;
 }