Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

happysquare's Profile

GitHub User: happysquare

Comments by

Avatar

So... after some tinkering I discovered a few things.
1. transform_command returns an array.
2. the resize is ahead of crop in the array, which means that the image is being resized, then cropped, which obviously won't work.

This very simple hack fixed the expected functionality:

ruby
def transformation_command
      if crop_command
        arr = super
        p "un modded #{arr}"
        arr[3] = crop_command

        p "modded #{arr}"
        [arr[2],arr[3],arr[0],arr[1],arr[4]]
      else
        super
      end
    end
    
    def crop_command
      target = @attachment.instance
      if target.cropping?
        "\"#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}\""
      end
    end

The array varies depending on the transform, so this is indeed an unreliable HACK.
I'd fix it, but I think I'll explore a CarrierWave solution instead.