Exemple #1
0
 /**
  * imagettftext is the function that is most likely to throw an error
  * use this custom error handler to catch and log it
  *
  * @param int    $errno
  * @param string $errstr
  *
  * @return bool
  */
 function imageTtfTextErrorHandler($errno, $errstr)
 {
     // log the error
     Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<');
     // change value of useTTF to false so the fallback watermarking can be used.
     $this->use_ttf = false;
     return true;
 }
 /**
  * Check if thumbnails from cache should be recreated
  * 
  * @param type $mediaobject
  * @return string filename
  */
 private function getThumbnail(Media $mediaobject)
 {
     $cache_dir = $this->cacheDir();
     if (!file_exists($cache_dir)) {
         File::mkdir($cache_dir);
     }
     if (file_exists($mediaobject->getServerFilename())) {
         $cache_filename = $this->cacheFileName($mediaobject);
         if (!is_file($cache_filename)) {
             $thumbnail = $this->fancyThumb($mediaobject);
             $mimetype = $mediaobject->mimeType();
             if ($mimetype === 'image/jpeg') {
                 imagejpeg($thumbnail, $cache_filename);
             } elseif ($mimetype === 'image/png') {
                 imagepng($thumbnail, $cache_filename);
             } else {
                 return;
             }
         }
         return $cache_filename;
     }
 }
Exemple #3
0
 }
 $oldFilename = $media->getFilename();
 $newFilename = $folderName . $fileName;
 // Cannot rename local to external or vice-versa
 if (Functions::isFileExternal($oldFilename) != Functions::isFileExternal($filename)) {
     FlashMessages::addMessage(I18N::translate('The media file %1$s could not be renamed to %2$s.', Html::filename($oldFilename), Html::filename($newFilename)));
     break;
 }
 $messages = false;
 $move_file = false;
 // Move files on disk (if we can) to reflect the change to the GEDCOM data
 if (!$media->isExternal()) {
     $oldServerFile = $media->getServerFilename('main');
     $oldServerThumb = $media->getServerFilename('thumb');
     $newmedia = new Media("xxx", "0 @xxx@ OBJE\n1 FILE " . $newFilename, null, $WT_TREE);
     $newServerFile = $newmedia->getServerFilename('main');
     $newServerThumb = $newmedia->getServerFilename('thumb');
     // We could be either renaming an existing file, or updating a record (with no valid file) to point to a new file
     if ($oldServerFile !== $newServerFile) {
         //-- check if the file is used in more than one gedcom
         //-- do not allow it to be moved or renamed if it is
         if (!$media->isExternal() && FunctionsDb::isMediaUsedInOtherTree($media->getFilename(), $WT_TREE->getTreeId())) {
             FlashMessages::addMessage(I18N::translate('This file is linked to another family tree on this server. It cannot be deleted, moved, or renamed until these links have been removed.'));
             break;
         }
         $move_file = true;
         if (!file_exists($newServerFile) || md5_file($oldServerFile) === md5_file($newServerFile)) {
             try {
                 rename($oldServerFile, $newServerFile);
                 FlashMessages::addMessage(I18N::translate('The media file %1$s has been renamed to %2$s.', Html::filename($oldFilename), Html::filename($newFilename)));
             } catch (\ErrorException $ex) {
Exemple #4
0
 /**
  * Create a new image object from Media Object - ReportPdf
  *
  * @param Media  $mediaobject
  * @param mixed  $x
  * @param mixed  $y
  * @param int    $w           Image width
  * @param int    $h           Image height
  * @param string $align       L:left, C:center, R:right or empty to use x/y
  * @param string $ln          T:same line, N:next line
  *
  * @return ReportPdfImage
  */
 public function createImageFromObject($mediaobject, $x, $y, $w, $h, $align, $ln)
 {
     return new ReportPdfImage($mediaobject->getServerFilename('thumb'), $x, $y, $w, $h, $align, $ln);
 }
 /**
  * Check if thumbnails from cache should be recreated
  *
  * @param type $mediaobject
  * @return string filename
  */
 private function getThumbnail(Media $mediaobject)
 {
     $cache_dir = $this->cacheDir();
     if (!file_exists($cache_dir)) {
         File::mkdir($cache_dir);
     }
     if (file_exists($mediaobject->getServerFilename())) {
         $cache_filename = $this->cacheFileName($mediaobject);
         if (!is_file($cache_filename)) {
             if ($this->options('resize_thumbs')) {
                 $thumbnail = $this->fancyThumb($mediaobject);
                 $mimetype = $mediaobject->mimeType();
                 if ($mimetype === 'image/jpeg') {
                     imagejpeg($thumbnail, $cache_filename);
                 } elseif ($mimetype === 'image/png') {
                     imagepng($thumbnail, $cache_filename);
                 } else {
                     return;
                 }
             } else {
                 // if we are using the original webtrees thumbnails, copy them to the ftv_cache folder
                 // so we can cache them either and output them in the same way we would output the fancy thumbnail.
                 try {
                     copy($mediaobject->getServerFilename('thumb'), $cache_filename);
                 } catch (Exception $ex) {
                     // something went wrong while copying the default webtrees image to the ftv cache folder
                     // there is a fallback in the function printThumbnail(): output $mediaobject->displayImage();
                 }
             }
         }
         return $cache_filename;
     }
 }