Example #1
0
 /**
  * Will generate a thumbnail for a given document
  */
 function ShowThumbnail($iID, $iPage, $iWidth)
 {
     $SQL = "SELECT documents.filename AS filename, documents.pagecount AS pages FROM documents LEFT JOIN rawtext ON (rawtext.document = documents.id) WHERE id = " . $iID;
     $res = mysql_query($SQL, $this->db);
     if ($res === FALSE) {
         return FALSE;
     }
     $aRes = mysql_fetch_array($res);
     if ($aRes === FALSE) {
         return FALSE;
     }
     if ($iPage < 1 || $iPage > $aRes["pages"]) {
         return FALSE;
     }
     // Split the thumbs off into their own directory
     $sFilename = $aRes["filename"];
     $sPath = dirname($sFilename);
     $sFile = basename($sFilename);
     // Create thumb directory
     if (!file_exists($sPath . "/thumbs")) {
         if (!mkdir($sPath . "/thumbs")) {
             return FALSE;
         }
         chgrp($sPath . "/thumbs", Config::getPermission("group"));
         chmod($sPath . "/thumbs", Config::getPermission("dirmask"));
     }
     $sThumbnail = sprintf("%s/thumbs/%s-%d-%d.png", $sPath, $sFile, $iWidth, $iPage);
     if (!file_exists($sThumbnail)) {
         // File doesn't exist, we need to generate one
         $sPrefix = uniqid();
         /*
         $sCmd = sprintf("/usr/bin/pdfimages -f %d -l %d %s /tmp/%s", $iPage, $iPage, $sFilename, $sPrefix);
         exec($sCmd);
         $sCmd = sprintf("/usr/bin/convert /tmp/%s-000.ppm -resize %dx %s", $sPrefix, $iWidth, $sThumbnail);
         exec($sCmd);
         */
         $sCmd = sprintf("/usr/bin/convert 2>&1 -depth 8  %s[%d] -resize %dx %s", $sFilename, $iPage - 1, $iWidth, $sThumbnail);
         exec($sCmd);
         //unlink(sprintf("/tmp/%s-000.ppm", $sPrefix));
         chgrp($sThumbnail, Config::getPermission("group"));
         chmod($sThumbnail, Config::getPermission("filemask"));
     }
     readfile($sThumbnail);
 }