Forum: Ruby on Rails attachment_fu Not Resizing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
72ee7b478a235f646c3495f03ebbe676?d=identicon&s=25 Andrew Stewart (Guest)
on 2007-03-28 12:45
(Received via mailing list)
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

The 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 Stewart
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-03-28 13:04
(Received via mailing list)
On Mar 28, 2007, at 12:43 PM, Andrew Stewart wrote:

> So it looks like the undefined constant prevents binary_data from
> being assigned.  But I don't know what to do about this.

Just in case it helps you moving on in the development while this is
understood, I found by chance that minimagick (which is enough for
me) works fine.

-- fxn
72ee7b478a235f646c3495f03ebbe676?d=identicon&s=25 Andrew Stewart (Guest)
on 2007-03-28 13:21
(Received via mailing list)
On 28 Mar 2007, at 11:54, Xavier Noria wrote:
> Just in case it helps you moving on in the development while this is
> understood, I found by chance that minimagick (which is enough for
> me) works fine.

Thanks for the suggestion.

RMagick does still work for me when I call it from straight Ruby --
which is what I am doing manually to resize images until my problem
is fixed.  This code looks like:

   require 'rubygems'
   require 'RMagick'

   ...

   img = Magick::Image.read(image_file).first   # image_file defined
above in snipped code
   img.change_geometry("300x") do |cols, rows, img|
     img.resize(cols, rows)
   end

So I think my RMagick installation is still okay....

Thanks for taking the time to reply (and sorry about my double post
with slightly different titles...user malfunction!).

Regards,
Andy Stewart
6c7d14e6938914ebac5b56928f61ab98?d=identicon&s=25 Xia __ (xia)
on 2007-05-30 09:03
Andrew are you devving on win xp? Incase others are finding this problem
thought i would mention that Heggie (of heggie.biz) discovered a
windows race condition bug with this plugin. He got some of it fixed
before we reverted back to acts_as_attachment for artabase.net

The problem seems to be with the plugin looking in the file system for
the file size, which isn't available immediately due to win xp taking a
few seconds to update it.

R.Cannon

Andrew Stewart wrote:
> 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.
....
This topic is locked and can not be replied to.