Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Resize_to_fill with Mini Magick adds 1 pixel white border #694

Closed
jebw opened this Issue · 9 comments

6 participants

@jebw

When resizing a 680x420px jpeg image to 80x49 using resize_to_fill with mini_magick a 1px white line is added to the left side of the image.

This is caused by the mogrify command actually resizing the image to 79pixels wide - the original command is

"mogrify -resize "80x49" -gravity "Center" -extent "80x45" /var/folders/6w/c3syy8g559g1vmkvcdn39l840000gn/T/mini_magick20120411-996-n6fw17-0.jpg"

This occurs on both Ubuntu 10.04 and Mac OS X (homebrew installed image magick)

Removing the extent and gravity options will actually resize the image to 79 pixels wide.

Changing the original command to only supply either an X resize or Y resize resolves this, retaining the full extent command.

@jebw

Potential fix at

jebw@f544a6c

@trevorturk
Owner

Care to work up a pull request? I'm not too familiar with MiniMagick, but maybe someone else can have a look before merging.

@jebw

I wasn't entirely convinced of my logic (though the code seems to be working well enough). I'll have a look back over it and submit a pull request if I think its right.

Are there any code submission requirements (ie tests?) - its manually tested at the moment, since it was a visual defect.

@trevorturk
Owner

Thanks! If you can come up with a way to test that makes sense, please do. Otherwise, just check your logic carefully and remember lots of people are going to use this, so please be careful! :)

@mariovisic

Hi guys, i'm also having this same problem? @jebw did you get a chance to test this out?

If not then I can test this for the images of one of my apps. Would be good to get this into master :P

@jebw
@mariovisic

@jebw awesome; thanks.

@bensie bensie closed this
@scarfacedeb

Hi.

I've been using v0.6.2 of this gem for a while.
I updated to the last version and found out that resize_to_fill doesn't work as it was working before.
(You can see the difference below)

The problem is that I need to crop images in the old way, without white borders.
For now I reverted to v0.6.2., but I'm curious - How could I have the crop from v0.6.2. using latest carrierwave?

v0.6.2
thumb_23740
v0.7.0
thumb_23740 1
original:
23740

@Mic92

Run into the same issue as @scarfaceDeb
This is what I use to solve it (basically the old code)

#lib/image_processing.rb
module ImageProcessing
    def resize_to_fill(width, height, gravity = 'Center')
      manipulate! do |img|
        cols, rows = img[:dimensions]
        img.combine_options do |cmd|
          if width != cols || height != rows
            scale = [width/cols.to_f,  height/rows.to_f].max
            cols = (scale * (cols + 0.5)).round
            rows = (scale * (rows + 0.5)).round
            cmd.resize "#{cols}x#{rows}"
          end
          cmd.gravity gravity
          cmd.background "rgba(255,255,255,0.0)"
          cmd.extent "#{width}x#{height}" if cols != width || rows != height
        end
        img
      end
    end
#

# app/uploaders/my_uploader.rb
class MyUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  include ImageProcessing

  version :thumb do
    # ...
    resize_to_fill(100, 100)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.