Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:34:42+00:00 2026-05-27T05:34:42+00:00

How do you scale down an image until one side reaches it’s goal dimension

  • 0

How do you scale down an image until one side reaches it’s goal dimension with Carrierwave and rmagick?

Example:

Goal dimensions: 600×400

Picture being uploaded: 700×450

I want this image to be scaled down until the height reaches 400 pixels keeping the original aspect ratio.

That would result in a image with the following dimensions: 622×400

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:34:42+00:00Added an answer on May 27, 2026 at 5:34 am

    You might take a look at resize_to_limit. From the carrierwave docs:

    Resize the image to fit within the specified dimensions while retaining the original aspect ratio. Will only resize the image if it is larger than the specified dimensions. The resulting image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.

    So you could do something like this in your uploader:

    process :resize_to_fill => [600, 400]
    

    If you don’t mind to crop the image, you could go for resize_to_fit instead, and use the gravity value that you desire:

    From the RMagick documentation: “Resize the image to fit within the specified dimensions while retaining the original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.“

    Edit:
    You can read the documentation for these processors for more options on resizing

    For a resize_to_min implementation that would only enforce minimum dimensions for your width and height, you can take resize_to_limit as base and just modify the geometry setting to MinimumGeometry to create a custom processor:

      process :resize_to_min => [600, 400]
    
      def resize_to_min(width, height)
        manipulate! do |img|
          geometry = Magick::Geometry.new(width, height, 0, 0, Magick::MinimumGeometry)
          new_img = img.change_geometry(geometry) do |new_width, new_height|
            img.resize(new_width, new_height)
          end
          destroy_image(img)
          new_img = yield(new_img) if block_given?
          new_img
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to scale down a image i get from photo library on
I'm not after saving an image, I just want to scale down an image
which algorithm to use to scale down 32Bit RGB IMAGE to custom resolution? Algorithm
i'm try to determine the amount to scale down an image, which is in
I need to scale down an image that has a height or width greater
I'm trying to scale an image down, change the image, then scale it back
I need to scale down an image, but in a sharp way. In Photoshop
Is there a way to scale down an image only if width is higher
So I want to scale an image down with css into the size of
Now I'm using the follow code to scale down the image downloaded from internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.