image = Magick::Image.read("filename").first
resized = image.resize_to_fit(width, height) # will maintain aspect ratio, so one of the resized dimensions may be less than the specified dimensions
resized.background_color = "#FFFFFF" # without a default, background color will vary based on the border of your original image
x = (resized.columns - width)/2 # calculate necessary translation to center image on background
y = (resized.rows - height)/2
resized = resized.extent(width, height, x, y) # 'extent' fills out the resized image if necessary, with the background color, to match the full requested dimensions. the x and y parameters calculated in the previous step center the image on the background.
resized.write("new_filename")
注:この投稿のようにImageMagickの6.5.7-8を使用Herokuの上に、私は-1 xとyの翻訳を乗算(正の数字を送信する)ために必要。バージョン6.8.0-10では負の数が必要です。