Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How to do convert this ImageMagick command and parameters into a Ruby code to be used with Carrierwave

Rails • Asked by W.M.

Basically I am asking how to do this:

convert input.png -bordercolor white -border 1 -set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]-%[fx:max((h-w)/2,0)]-%[fx:max((w-h)/2,0)]" -virtual-pixel edge -distort SRT 0 output.png

inside a Carrierwave uploader class.

Note: this command makes rectangular images into squares with white background.

Thank you.

Thanks to Jancko-m at github, he provided the following solution: do |cmd|
  convert << "input.png"
  convert.set("option:distort:viewport", "%[fx:max(w,h)]x%[fx:max(w,h)]-%[fx:max((h-w)/2,0)]-%[fx:max((w-h)/2,0)]")
  convert.distort("SRT", "0")
  convert << "output.png"

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.