attachment_fu doesn't have cropping, I'm trying to bake some in using ImageScience.
Firstly this requires the enabling of the '!' modifier in the geometry.rb file. However in the to_s method I don't think it's passing out the flags correctly. So I changed 'FLAGS[@flag.to_i]' to 'RFLAGS.index(@flag)' on line 47.
However now I need to change the logic in the image_science_processor.rb file to recognise the "!" aspect flag and then execute the crop and resize.
My issue is in doing two transformations, I don't really understand what the &grab_dimensions argument passed to the with_crop and resize methods is doing... please excuse my noob-ness.
I post my modified resize_image method to see if anyone can help...
def resize_image(img, size) # create a dummy temp file to write to self.temp_path = write_to_temp_file(filename) grab_dimensions = lambda do |img| self.width = img.width if respond_to?(:width) self.height = img.height if respond_to?(:height) img.save temp_path callback_with_args :after_resize, img end
size = size.first if size.is_a?(Array) && size.length == 1 if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a? (Fixnum)) if size.is_a?(Fixnum) img.thumbnail(size, &grab_dimensions) else img.resize(size[0], size[1], &grab_dimensions) end else new_size = [img.width, img.height] / size.to_s # Added logic here if size.ends_with? "!" aspect = new_size[0].to_f / new_size[1].to_f ih, iw = img.height, img.width w, h = (ih * aspect), (iw / aspect) w = [iw, w].min.to_i h = [ih, h].min.to_i
# THIS IS WHERE THE ISSUE IS! img.with_crop( iw/2-w/2, ih/2-h/2, iw/2+w/2, ih/2+h/2, &grab_dimensions ) img.resize(new_size[0], new_size[1], &grab_dimensions )
else img.resize(new_size[0], new_size[1], &grab_dimensions) end end end