# Attachment\_fu Resizing Mysteriously Stopped Working

**URL:** <https://www.ruby-forum.com/t/attachment-fu-resizing-mysteriously-stopped-working/90398>\
**Category:** Rails\
**Created:** [March 28, 2007, 1:07pm UTC](https://www.ruby-forum.com/t/attachment-fu-resizing-mysteriously-stopped-working/90398 "2007-03-28T13:07:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [March 28, 2007, 1:07pm UTC](https://www.ruby-forum.com/t/attachment-fu-resizing-mysteriously-stopped-working/90398/1 "2007-03-28T13:07:55Z")

</div>

Hello,

Recently attachment\_fu stopped resizing images for me. I’m puzzled  
because before today it was resizing them and I don’t know what’s  
changed. Here’s my code:

class Product \< ActiveRecord::Base  
has\_attachment :content\_type =\> :image,  
:storage =\> :file\_system,  
:max\_size =\> 18.megabytes,  
:resize\_to =\> ‘300x’,  
:thumbnails =\> { :thumb =\> ‘61x110!’ }  
validates\_as\_attachment  
end

I expected a 420x595 image to be resized to 300xWhatever and a 61x110  
thumbnail to be created. The image and thumbnail product records  
were both created in the database but the images were left at the  
original size.

Strangely the width and height fields in the database are no longer  
being set. For new uploads they are null whereas previously they had  
been set to the measurements of the resized images.

I think I’ve traced the problem to this method (but I could equally  
well be barking up the wrong tree):

attachment\_fu/processors/rmagick\_processor.rb:

```
        module ClassMethods
        # Yields a block containing an RMagick Image for the given

```

binary data.  
def with\_image(file, &block)  
begin  
binary\_data = file.is\_a?(Magick::Image) ? file :  
Magick::Image.read(file).first unless !Object.const\_defined?(:Magick)  
puts “binary\_data.nil? : #{binary\_data.nil?}”  
puts “file.nil?: #{file.nil?}”  
puts “const\_defined? : #{Object.const\_defined?  
(:Magick)}”  
rescue  
# Log the failure to load the image. This should  
match ::Magick::ImageMagickError  
# but that would cause acts\_as\_attachment to require  
rmagick.  
logger.debug(“Exception working with image: #{$!}”)  
binary\_data = nil  
end  
block.call binary\_data if block && binary\_data  
ensure  
!binary\_data.nil?  
end  
end

My puts statements give this output:

binary\_data.nil? : true  
file.nil?: false  
const\_defined? : false

So it looks like the undefined constant prevents binary\_data from  
being assigned. But I don’t know what to do about this.

I’d appreciate any help.

Thanks and regards,  
Andy S.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [April 3, 2007, 1:27pm UTC](https://www.ruby-forum.com/t/attachment-fu-resizing-mysteriously-stopped-working/90398/2 "2007-04-03T13:27:17Z")

</div>

On 28 Mar 2007, at 11:49, Andrew S. wrote:

> Recently attachment\_fu stopped resizing images for me. I’m puzzled  
> because before today it was resizing them and I don’t know what’s  
> changed. Here’s my code:

Just for the record, I found the cause of the problem.

Originally I installed attachment\_fu and created all my Product  
instances. Every image was resized perfectly.

Then I tried to interact with these Products in the console but  
RMagick kept blowing up with this error:

> > Product.find 1  
> > /usr/local/lib/ruby/gems/1.8/gems/rmagick-1.14.1/lib/  
> > RMagick.bundle: [BUG] Bus Error  
> > ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0]

Abort trap

To get round this, I added a one-line file called RMagick.rb to my  
lib/ directory. This was recommended by Rick O. somewhere on the  
Mephisto site.

lib/RMagick.rb:

```
 raise LoadError

```

Hooray! Now the console works:

> > Product.find 1  
> > =\> #\<Product:0x2663628 @attributes={“content\_type”=\>“image/jpeg”,  
> > “name”=\>…blah…}

Unfortunately this prevents attachment\_fu from resizing images  
uploaded via a form. So to create new products via the form I have  
to move the lib/RMagick.rb hack away first.

Hope this helps somebody else.

Regards,  
Andy S.
