Author: uncleringo
Date: 2010-02-16 13:56:47 +0100 (Tue, 16 Feb 2010)
New Revision: 28053

Modified:
   plugins/sfDoctrineJCroppablePlugin/trunk/lib/doctrine/JCroppable.php
Log:
Now allows the loading of images from the data/images dir when doing a 
'./symfony doctrine:build --all --and-load' etc
Note you only need to have the editable version (without _{image name}) in the 
data/images dir
The plugin will create all the cropped versions of the using the fixtures data



Modified: plugins/sfDoctrineJCroppablePlugin/trunk/lib/doctrine/JCroppable.php
===================================================================
--- plugins/sfDoctrineJCroppablePlugin/trunk/lib/doctrine/JCroppable.php        
2010-02-16 12:43:40 UTC (rev 28052)
+++ plugins/sfDoctrineJCroppablePlugin/trunk/lib/doctrine/JCroppable.php        
2010-02-16 12:56:47 UTC (rev 28053)
@@ -253,30 +253,59 @@
     }
     
     $dir = $this->getImageDir();
-    
+
+    $from = $dir . DIRECTORY_SEPARATOR . $editable;
+    $to = $dir . DIRECTORY_SEPARATOR . $original;
+
     /**
-     * Move the new image to be named as the original
+     * If we can't find the image
      */
-    rename($dir . DIRECTORY_SEPARATOR . $editable, $dir . DIRECTORY_SEPARATOR 
. $original);
-    //print("mv $editable $original<br/>");exit;
+    if (!file_exists($from))
+    {
+      /**
+       * Check if we're loading data rather than saving via the admin interface
+       *  and look for the image in the data/images dir
+       */
+      if (!sfContext::hasInstance() && file_exists('data/images/' . $editable))
+      {
+        print('Found data/images/' . $editable . "\n");
+        copy('data/images/' . $editable, $to);
+      }
+      /**
+       * We don't have the original for some reason and we can't find a data
+       * copy so best just return
+       */
+      else
+      {
+        return;
+      }
+    }
+    else
+    {
+      /**
+       * Move the new image to be named as the original
+       */
+      rename($from, $to);
+    }
+    
     /**
      * Load the original and resize it for the editable version
      */
     $img = new sfImage($dir . DIRECTORY_SEPARATOR . $original);
     
-    if (isset($imageConfig['padding'])) {
+    if (sfContext::hasInstance() && isset($imageConfig['padding'])) {
       $img = $this->addPadding($img, $imageConfig['padding']);
       
       $img->saveAs($dir . DIRECTORY_SEPARATOR . $original);
+      
+      $this->getInvoker()->{$fieldName . '_x1'} = 0;
+      $this->getInvoker()->{$fieldName . '_y1'} = 0;
+      $this->getInvoker()->{$fieldName . '_x2'} = $img->getWidth();
+      $this->getInvoker()->{$fieldName . '_y2'} = $img->getHeight();
     }
-    
+
     $img->resize(400, null);
     $img->saveAs($dir . DIRECTORY_SEPARATOR . $editable);
-    
-    $this->getInvoker()->{$fieldName . '_x1'} = 0;
-    $this->getInvoker()->{$fieldName . '_y1'} = 0;
-    $this->getInvoker()->{$fieldName . '_x2'} = $img->getWidth();
-    $this->getInvoker()->{$fieldName . '_y2'} = $img->getHeight();
   }
   
   /**

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" 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/symfony-svn?hl=en.

Reply via email to