<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -23,6 +23,8 @@
     * added support for file_column enabled unit tests [Manuel Holtgrewe]
     * support for custom transformation of images [Frederik Fix]
     * allow setting of image attributes (e.g., quality) [Frederik Fix]
+    * :magick columns can optionally ignore non-images (i.e., do not try to
+       resize them)
 
 0.3.1
     * make object with file_columns serializable</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -130,7 +130,8 @@ module FileColumnHelper
   # although it will start with a slash.
   # If you pass this URL to rails' +image_tag+ helper, it will be converted to an
   # absolute URL automatically.
-  # If there is currently no image uploaded, this method will return +nil+.
+  # If there is currently no image uploaded, or there is a problem while loading
+  # the image this method will return +nil+.
   def url_for_image_column(object, method, options=nil)
     case object
     when String, Symbol
@@ -140,6 +141,10 @@ module FileColumnHelper
     if options
       subdir = object.send(&quot;#{method}_state&quot;).create_magick_version_if_needed(options)
     end
-    url_for_file_column(object, method, subdir)
+    if subdir.nil?
+      nil
+    else
+      url_for_file_column(object, method, subdir)
+    end
   end
 end</diff>
      <filename>lib/file_column_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,8 +6,10 @@ module FileColumn # :nodoc:
         begin
           img = ::Magick::Image::read(absolute_path).first
         rescue ::Magick::ImageMagickError
-          @magick_errors ||= []
-          @magick_errors &lt;&lt; &quot;invalid image&quot;
+          if options[:magick][:image_required]
+            @magick_errors ||= []
+            @magick_errors &lt;&lt; &quot;invalid image&quot;
+          end
           return
         end
         
@@ -45,7 +47,13 @@ module FileColumn # :nodoc:
       end
 
       unless File.exists?(absolute_path(version_options[:name]))
-        img = ::Magick::Image::read(absolute_path).first
+        begin
+          img = ::Magick::Image::read(absolute_path).first
+        rescue ::Magick::ImageMagickError
+          # we might be called directly from the view here
+          # so we just return nil if we cannot load the image
+          return nil
+        end
         dirname = version_options[:name]
         FileUtils.mkdir File.join(@dir, dirname)
         transform_image(img, version_options, absolute_path(dirname))
@@ -119,6 +127,15 @@ module FileColumn # :nodoc:
   #
   #    file_column :image, :magick =&gt; {:size =&gt; &quot;800x600&gt;&quot;}
   #
+  # If the uploaded file cannot be loaded by RMagick, file_column will
+  # signal a validation error for the corresponding attribute. If you
+  # want to allow non-image files to be uploaded in a column that uses
+  # the &lt;tt&gt;:magick&lt;/tt&gt; option, you can set the &lt;tt&gt;:image_required&lt;/tt&gt;
+  # attribute to +false+:
+  #
+  #    file_column :image, :magick =&gt; {:size =&gt; &quot;800x600&gt;&quot;,
+  #                                    :image_required =&gt; false }
+  #
   # == Multiple versions
   #
   # You can also create additional versions of your image, for example
@@ -224,6 +241,7 @@ module FileColumn # :nodoc:
       if options[:geometry]
         options[:size] = options.delete(:geometry)
       end
+      options[:image_required] = true unless options.key?(:image_required)
       if options[:name].nil? and create_name
         if create_name == true
           hash = 0</diff>
      <filename>lib/magick_file_column.rb</filename>
    </modified>
    <modified>
      <diff>@@ -91,6 +91,41 @@ class RMagickSimpleTest &lt; AbstractRMagickTest
   end
 end
 
+class RMagickRequiresImageTest &lt; AbstractRMagickTest
+  def setup
+    Entry.file_column :image, :magick =&gt; { 
+      :size =&gt; &quot;100x100&gt;&quot;,
+      :image_required =&gt; false,
+      :versions =&gt; {
+        :thumb =&gt; &quot;80x80&gt;&quot;,
+        :large =&gt; {:size =&gt; &quot;200x200&gt;&quot;, :lazy =&gt; true}
+      }
+    }
+  end
+
+  def test_image_required_with_image
+    e = Entry.new(:image =&gt; upload(f(&quot;skanthak.png&quot;)))
+    assert_max_image_size read_image(e.image), 100
+    assert e.valid?
+  end
+
+  def test_image_required_with_invalid_image
+    e = Entry.new(:image =&gt; upload(f(&quot;invalid-image.jpg&quot;)))
+    assert e.valid?, &quot;did not ignore invalid image&quot;
+    assert FileUtils.identical?(e.image, f(&quot;invalid-image.jpg&quot;)), &quot;uploaded file has not been left alone&quot;
+  end
+
+  def test_versions_with_invalid_image
+    e = Entry.new(:image =&gt; upload(f(&quot;invalid-image.jpg&quot;)))
+    assert e.valid?
+
+    image_state = e.send(:image_state)
+    assert_nil image_state.create_magick_version_if_needed(:thumb)
+    assert_nil image_state.create_magick_version_if_needed(:large)
+    assert_nil image_state.create_magick_version_if_needed(&quot;300x300&gt;&quot;)
+  end
+end
+
 class RMagickCustomAttributesTest &lt; AbstractRMagickTest
   def assert_image_property(img, property, value, text = nil)
     assert File.exists?(img), &quot;the image does not exist&quot;</diff>
      <filename>test/magick_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3993bf382c7187588baee4f755e1707180657d88</id>
    </parent>
  </parents>
  <author>
    <name>skanthak</name>
    <email>skanthak@6a5db2c9-b104-0410-84e5-917aad89f9d9</email>
  </author>
  <url>http://github.com/kch/file_column/commit/bd5b1c6c3e4cf180c4ad6b86ac9532c0183fe795</url>
  <id>bd5b1c6c3e4cf180c4ad6b86ac9532c0183fe795</id>
  <committed-date>2006-04-24T13:57:41-07:00</committed-date>
  <authored-date>2006-04-24T13:57:41-07:00</authored-date>
  <message>:magick columns can ignore non-image files


git-svn-id: http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk@64 6a5db2c9-b104-0410-84e5-917aad89f9d9</message>
  <tree>cbc7f6ea19b0139aafc45d9d52bd9f0b1f16422a</tree>
  <committer>
    <name>skanthak</name>
    <email>skanthak@6a5db2c9-b104-0410-84e5-917aad89f9d9</email>
  </committer>
</commit>
