Author: jablko
Date: Tue Dec  1 15:25:59 2009
New Revision: 4020

Log:
Cosmetic changes

Modified:
   trunk/lib/model/QubitDigitalObject.php

Modified: trunk/lib/model/QubitDigitalObject.php
==============================================================================
--- trunk/lib/model/QubitDigitalObject.php      Tue Dec  1 15:13:36 2009        
(r4019)
+++ trunk/lib/model/QubitDigitalObject.php      Tue Dec  1 15:25:59 2009        
(r4020)
@@ -893,7 +893,9 @@
   {
     if ($this->canThumbnail() && self::hasImageMagick())
     {
-      exec('identify '.sfConfig::get('sf_web_dir').$this->getFullPath(), 
$output, $status);
+      $command = 'identify '.sfConfig::get('sf_web_dir').$this->getFullPath();
+      exec($command, $output, $status);
+
       if ($status == 0)
       {
         // Add "number of pages" property
@@ -941,11 +943,10 @@
     {
       $filenameMinusExtension = preg_replace('/\.[a-zA-Z]{2,3}$/', '', 
$this->getFullPath());
 
-      $convertStr  = 'convert -quality 100 ';
-      $convertStr .= sfConfig::get('sf_web_dir').$this->getFullPath();
-      $convertStr .= ' 
'.sfConfig::get('sf_web_dir').$filenameMinusExtension.'_%02d.'.self::THUMB_EXTENSION;
-
-      exec($convertStr, $output, $status);
+      $command = 'convert -quality 100 ';
+      $command .= sfConfig::get('sf_web_dir').$this->getFullPath();
+      $command .= ' 
'.sfConfig::get('sf_web_dir').$filenameMinusExtension.'_%02d.'.self::THUMB_EXTENSION;
+      exec($command, $output, $status);
 
       if ($status == 1)
       {
@@ -1304,15 +1305,10 @@
    */
   public static function hasImageMagick()
   {
-    $found = false;
+    $command = 'convert -version';
+    exec($command, $output, $status);
 
-    exec('convert -version', $stdout);
-    if (count($stdout) && strpos($stdout[0], 'ImageMagick') !== false)
-    {
-      $found = true;
-    }
-
-    return $found;
+    return 0 < count($output) && false !== strpos($output[0], 'ImageMagick');
   }
 
   /**
@@ -1322,13 +1318,7 @@
    */
   public static function hasGdExtension()
   {
-    $found = false;
-    if (extension_loaded('gd'))
-    {
-      $found = true;
-    }
-
-    return $found;
+    return extension_loaded('gd');
   }
 
   /**
@@ -1449,15 +1439,10 @@
    */
   public static function hasFfmpeg()
   {
-    $found = false;
-
-    exec('ffmpeg -version 2>&1', $stdout, $returnValue);
-    if (0 < count($stdout) && strpos($stdout[0], 'FFmpeg') !== false)
-    {
-      $found = true;
-    }
+    $command = 'ffmpeg -version 2>&1';
+    exec($command, $output, $status);
 
-    return $found;
+    return 0 < count($output) && false !== strpos($output[0], 'FFmpeg');
   }
 
   /**
@@ -1477,18 +1462,19 @@
     // Test for FFmpeg library
     if (!self::hasFfmpeg())
     {
-
       return false;
     }
 
-    exec('ffmpeg -y -i '.$originalPath.' '.$newPath.' 2>&1', $stdout, 
$returnValue);
-    chmod($newPath, 0644);
+    $command = 'ffmpeg -y -i '.$originalPath.' '.$newPath.' 2>&1';
+    exec($command, $output, $status);
 
     // If return value is non-zero, an error occured
-    // if ($returnValue)
-    // {
-    //   throw new sfException('Encountered error while running ffmpeg.');
-    // }
+    if ($status)
+    {
+      throw new sfException($command.' '.$output.' '.$status);
+    }
+
+    chmod($newPath, 0644);
 
     return true;
   }
@@ -1505,25 +1491,25 @@
    *
    * @todo implement $maxwidth and $maxheight constraints on video
    */
-  public static function convertVideoToThumbnail($originalPath, $newPath, 
$width=null, $height=null)
+  public static function convertVideoToThumbnail($originalPath, $newPath, 
$width = null, $height = null)
   {
     // Test for FFmpeg library
     if (!self::hasFfmpeg())
     {
-
       return false;
     }
 
     // Do conversion to jpeg
-    $cmd = 'ffmpeg -i '.$originalPath.' -vframes 1 -an -f image2 -s 
'.$width.'x'.$height.' '.$newPath;
-    exec($cmd.' 2>&1', $stdout, $returnValue);
-    chmod($newPath, 0644);
+    $command = 'ffmpeg -i '.$originalPath.' -vframes 1 -an -f image2 -s 
'.$width.'x'.$height.' '.$newPath;
+    exec($command.' 2>&1', $output, $status);
 
     // If return value is non-zero, an error occured
-    // if ($returnValue)
-    // {
-    //   throw new sfException('Encountered error while running ffmpeg.');
-    // }
+    if ($status)
+    {
+      throw new sfException($command.' '.$output.' '.$status);
+    }
+
+    chmod($newPath, 0644);
 
     return true;
   }
@@ -1583,15 +1569,16 @@
     }
 
     // Do conversion to jpeg
-    $cmd = 'ffmpeg -i '.$originalPath.' -vframes 1 -an -f image2 -s 
'.$width.'x'.$height.' '.$tmpFilePath;
-    exec($cmd.' 2>&1', $stdout, $returnValue);
-    chmod($tmpFilePath, 0644);
+    $command = 'ffmpeg -i '.$originalPath.' -vframes 1 -an -f image2 -s 
'.$width.'x'.$height.' '.$tmpFilePath.' 2>&1';
+    exec($command, $output, $status);
 
     // If return value is non-zero, an error occured
-    // if ($returnValue)
-    // {
-    //   throw new sfException('Encountered error while running ffmpeg.');
-    // }
+    if ($status)
+    {
+      throw new sfException($command.' '.$output.' '.$status);
+    }
+
+    chmod($tmpFilePath, 0644);
 
     return file_get_contents($tmpFilePath);
   }

--

You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.


Reply via email to