Thursday, March 31, 2011

Getting error: The specified module could not be found. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so (LoadError )

After installing pik, added Ruby 1.9.2 and then switched to Ruby 1.9.2, installed rails on Ruby 1.9.2.
On my existing rails application which has already been updated to Rails -v 3.0.3, I ran 'bundle install' and it executed and installed the gems. Tried to run rails server, but got error:


>rails s
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/mysql.rb:7:in `require': 126: The specified module could not be found.   - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so (LoadError
)
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/mysql.rb:7:in `rescue in <top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/mysql.rb:2:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `block in require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
        from C:/projects/working project/phoenix/config/application.rb:7:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

To fix this error, I copied "libmySQL.dll" file from 'C:\Program Files\MySQL\MySQL Server 5.1\bin' to 'C:\Ruby192\bin' and then on starting the server it ran without any error.

Getting `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError) while creating new rails application after installing pik gem

In my previous post "steps-to-install-pik-add-ruby-to-pik.html", described how to install pik on windows, adding ruby version to pik and switching between various ruby versions through pik.

After installing pik, added Ruby 1.9.2 and then switched to Ruby 1.9.2:

>pik 192
>pik list
   187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
* 192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

When I checked rails version after switching Ruby version to 1.9.2, I got error.

>rails -v
'rails' is not recognized as an internal or external command,
operable program or batch file.

Tried to create new rails application, but again got error:
>rails new demos
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:861:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:255:in `activate'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:1204:in `gem'
        from C:/Ruby187/bin/rails:18:in `<main>'

To fix this problem, I installed rails gem in Ruby 1.9.2
>gem install rails

And then I checked rails version.
>rails -v
Rails 3.0.5

I was able to create new rails application. 
On my existing rails application which has already been updated to Rails -v 3.0.3, I ran 'bundle install' and it executed and installed the gems listed in Gemfile.

Steps to install pik, add ruby to pik list and switch between Ruby version

I use Pik to manage multiple versions of ruby on a Windows machine. Here are the steps to install pik:

Install the pik gem
> gem install pik
......
Successfully installed pik-0.2.8
1 gem installed

Then check path
>path
PATH=C:\Program Files\ImageMagick-6.6.4-Q16;C:\Program Files\ImageMagick-6.5.6-Q8;C:\Windows\system32;C:\Program Files\Git\bin;C:\Program Files\Git\cmd; C:\Ruby187\bin

Then Install pik to a location other than your ruby\bin dir. I used C:\pik

>pik_install C:\pik
Thank you for using pik.
Installing to C:\pik
...
pik is installed

It will install pik and will create a folder 'pik' in C:\ drive. You will get 'C:\pik'
Now add the variable 'C:\pik' in your 'Environmental Variables' path.

For steps to add path in 'Environmental Variables' or troubleshooting the setup of 'Environmental Variables', please see post "setting-path-cpik-in-environmental-variable"

Download Ruby 1.9.2 exe from http://rubyforge.org/frs/download.php/74298/rubyinstaller-1.9.2-p180.exe
Install and add the new Ruby version to pik registry.

>pik add C:\Ruby192\bin

You can check the List of all available Ruby versions added in pik, one with the '*' sign displays the default one:

>pik list
* 187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
   192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]


>ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]


To switch to Ruby 1.9.2:

>pik 192
>pik list
   187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
* 192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]



>ruby -v
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

To switch back to Ruby 1.8.7:
>pik 187

Its over and pik is successfully installed, now you know how to install pik, add ruby to pik list and switch between Ruby version

Setting path 'C:\pik' in 'Environmental Variables'

To access the environment variables right click the My Computer icon then choose properties. Click 'Advanced system settings' link, click on 'Advanced' tab and then click 'Environment Variables'. In 'system variables, select 'Path' variable and click on Edit.
In the end of 'Variable Value'. add semicolon and C:\pik
;C:\pik
Click on Ok to save the settings.
In this way, you can set any variables path.

Installing mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows


When running 'bundle install' or 'gem install mysql2', I got following error:
>gem install mysql2
ERROR:  Error installing mysql2:
        The 'mysql2' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
 To solve this issue and to successfully install mysql2 gem, I took following steps:

1. Download Development Kit "http://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe" from http://rubyinstaller.org/downloads/
2. Followed the instructions given on link https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
3. Extracted the downloaded DevKit.
4. cd <DEVKIT_INSTALL_DIR>
5. run ruby dk.rb init.

C:\Users\ritesh\Downloads\DevKit-tdm-32-4.5.1-20101214-1400-sfx>ruby dk.rb init
[INFO] found RubyInstaller v1.9.2 at C:/Ruby192
[INFO] found RubyInstaller v1.8.7 at C:/Ruby187

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

6. edit the generated config.yml file as per your system available Rubies version if required
7. [optional] ruby dk.rb review to verify the changes you made to it are correct.

8. finally, ruby dk.rb install to DevKit enhance your installed Rubies.


C:\Users\ritesh\Downloads\DevKit-tdm-32-4.5.1-20101214-1400-sfx>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby192'
[INFO] Installing 'C:/Ruby192/lib/ruby/site_ruby/devkit.rb'
[INFO] Skipping existing gem override for 'C:/Ruby187'
[WARN] Skipping existing DevKit helper library for 'C:/Ruby187'

9. You have successfully installed the DevKit, and now comes the step to install mysql2 gem, most important one for which we took so many steps. Make sure you are using Ruby 1.9.2 version.

10. Run gem install myql2 with parameters that I have passed, path can differ for you so make changes accordingly.

>gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.1\lib\opt" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.1\include"'
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.7
1 gem installed
Installing ri documentation for mysql2-0.2.7...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.7...
Enclosing class/module 'mMysql2' for class Client not known

And, congrats, you are done with installation of Mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows.

Pik & RVM, tools to manage multiple Ruby versions on Windows, OS X, Linux

I have a Rails application that I have upgraded from Rails 2.3.5 to Rails 3.0.3. Removed deprecations and made that application stable on Rails 3.0.3. And now, it was Ruby turn to be upgraded from
 - Ruby 1.8.7 to Ruby 1.9.2.

This Ruby Migration was really going to be a challenging one because of two reasons:
Firstly, My application is running on Windows as well as on Linux, Ubuntu, Mac.
Secondly, I need both Ruby versions, 1.8.7 and 1.9.2 for my application because I don't know how my application will behave with Ruby 1.9.2, what are the things that will break, so be on safer side  I want both versions.

My basic requirement was to be able to switch between Ruby versions easily so that rest of my work doesn't get impacted because of Ruby upgradation. I have heard of RVM (Ruby Version Manager) that makes it easy to install and switch between multiple Ruby versions on OS X and Linux.

But, sadly RVM cannot be used on Windows. Now what! To my rescue, came another gud tool, Pik.

Pik is a tool to manage multiple versions of ruby on Windows. It can be used from the Windows command line (cmd.exe), Windows PowerShell, or Git Bash. Very much similar to RVM.

In next few blogs, watch how to install Pik, upgrade Ruby version to 1.9.2 on Windows and challenges faced during upgradation.

Tuesday, March 29, 2011

RubyBarcamp4 "round table" discussions in Kyiv, April 9, 2011

RubyBarcamp4 are inviting to take part in unusual format of "round table" discussions, which will take place in Kyiv, April 9, 2011.
Moderators with their Topics for discussions are as follows:
  • Problems of architecture of big RoR projects. moderator of discussion Slava Dodatko
  • HighLoad Projects. moderator of discussion Stanislav Pogrebnyak
  • Server side tasks, deploy on server. moderator of discussion Dmitry Shaposhnik
  • User Interfaces. moderator Michael Bilenko
Everyone who has necessary experience can take part in the discussions. Participation is free but registration is necessary. The registration will be closed at April 5.

For details, please refer to the site: http://rubylang.org.ua/events/12

Wednesday, March 23, 2011

I18n::MissingTranslationData, translation missing: ja, number, human, storage_units, format

While translating the application in Japanese language, I got following error:

I18n::MissingTranslationData in Campaigns#campaign_upload
Showing C:/projects/demoapp/app/views/campaigns/_update_uploads.html.erb where line #20 raised:
translation missing: ja, number, human, storage_units, format

For line:
<%=number_to_human_size(asset.attachment_file_size)%>

Error displays that some translation is missing for ja, number, human, storage_units, format.

To fix the error:
 
Changed the code in view to include locale params:
<%=number_to_human_size(asset.attachment_file_size, :locale=>I18n.locale)%>

Added following codes in config\locales\ja.yml file :
ja:
 number:   
    format:
      separator: "."
      delimiter: ","
      precision: 3
      significant: false
      strip_insignificant_zeros: false   

    # Used in number_to_human_size() and number_to_human()
    human:
      format:
        delimiter: ""
        precision: 3
        significant: true
        strip_insignificant_zeros: true

      # Used in number_to_human_size()
      storage_units:
        format: "%n %u"
        units:
          byte:
            one: "Byte"
            other: "Bytes"
          kb: "KB"
          mb: "MB"
          gb: "GB"
          tb: "TB"

      # Used in number_to_human()
      decimal_units:
        format: "%n %u"
        units:
          # femto: Quadrillionth
          # pico: Trillionth
          # nano: Billionth
          # micro: Millionth
          # mili: Thousandth
          # centi: Hundredth
          # deci: Tenth
          unit: ""
          # ten:
          # one: Ten
          # other: Tens
          # hundred: Hundred
          thousand: Thousand
          million: Million
          billion: Billion
          trillion: Trillion
          quadrillion: Quadrillion

Although the above codes are in English language, you can get the above code in  Japanese or any other languages also, which will fix number_to_human_size  error..

Tuesday, March 22, 2011

Setting Git executable path in RubyMine 3.0

Sometimes, when you do changes in Rails application and want to see the changes in RubyMine 3.0, it displays NO changes although there are files that has been changed. When you try to commit and push the code with Git you are not able to do so, you get error that path could not be located.

To make RubyMine 3.0 work with Git, you have to set 'Path to git executable'.
Click on File, open File -> Settings -> Version Control -> VCSs -> Git and set 'Path to git executable'. In Windows7 in my case it's "C:\Program Files\Git\bin\git.exe"


Click on OK.
Restart RubyMine and your path to Git is set, you will be able to commit and push the code now.

Localization in Rails3

Localization, also known as internationalization is the process of changing the complete site content in some other languages. In Rails 3, all dependencies for localization are already included in i18n library, you only require few codes as given below:

In Application controller, add
before_filter :set_locale

  def set_locale
    I18n.locale = params[:locale]
  end

Add in config/initializers/global.rb (If global.rb is not there, add the file)
I18n.default_locale = :en
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

In config/locales, en.yml file is already there with content:
en:
  hello: "Hello world"

Add one file, say fr.yml (fr stands for French, but you can name it anything)
fr:
  hello: " French Hello world "

Now change any static content in the any view, I am changing 'Username' in login page view with 
<%= t('hello')%>

Open the page in browser, http://localhost:3000/login will display 'Hello world' in place of 'Username' because by default locale is set as english in global.rb setting.
Change the url as http://localhost:3000/login?locale=en will display 'Hello world'
Now change the url as http://localhost:3000/login?locale=fr, it will display 'French Hello world'.

This way you can change any static content of the site to any language. 

Wednesday, March 16, 2011

WYSIWYG editor for Rails3

If you are looking for a WYSIWYG editor for Rails3, then NicEdit is the one of the best editor.

NicEdit is a Lightweight and Inline Content Editor which is pretty easy to install and use with Rails application.
This can also be used with Rails3 latest version.

Steps to install:
  • Download nicEdit.js file from http://nicedit.com/index.php
  • Copy and paste the file in public/javascripts folder
  • Include js file in layout.
    <%= javascript_include_tag 'nicEdit' -%>
  • Paste following code above the form where you want to display Editor
<script type="text/javascript">
       bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>
For ex- If you want to display the Editor in Users new form then paste the code above that form.
And thats it!
Any text area in that form will be displaying NicEditor with rows and columns which you mention
<%= f.text_area :news, :cols=>"100", :rows=>"15" %>

Friday, March 11, 2011

How to resize pics stored in different -2 folder through ImageMagick from Ruby on Rails application

In one of the Ruby on Rails application, I am using attachment_fu plugin, asset model used as polymorphic to upload image from various model and ImageMagick.

When the application went into production, we were uploading images and resizing to 2 different sizes, later on we found that one more size is required which will be used in the application to display the image. Now big issue was, how to resize all the uploaded image in a specific desired size in production.

One way was to download all the assets folder and then one by one resize them and rename them accordingly and then place them in their respective folder. But that was not good way as lots of effort, time and risk was involved in that.

After thinking on all the possible ways, we decided to make one method in model which will pick the collection of all the images one by one, resize them and then restore in the destination folder. This was certainly one of the most effective way of doing it. But this method will not be required again and again, so why not to have a rake task that will work instead of a method in the model.

So, at last, after lots of deep thinking, we decided to go with the rake task option which will pick images one by one, resize them and will save them in their respective folder with desired name.

Here is the code snippets to do that:

desc "Create missing featured image"
    task :create_featured_image => :environment do
      clips = Clip.all.collect
      clips.each do |fi|
        if !fi.blank? && !fi.asset.blank? && !fi.asset.public_filename(:featured).blank?
          original_image = RAILS_ROOT +  "/public/" + "#{fi.asset.public_filename}"

          destination_image = RAILS_ROOT + "/public/" + "#{fi.asset.public_filename(:featured)}"

          if !FileTest.exists?(destination_image)
            p "converting image #{fi.id}"
            system("convert  #{original_image}   -resize 250x155! #{destination_image}")
          end
        end
      end
    end


In the above code, we have taken the collection of clips, iterating over that collection, picking clip object one by one, checking if the original image exists, if yes then it will check if new image that needs to be created is already present, if no then it will create that new image, else it will not create. While execution it will show on the console which image it is resizing.

How to resize all pics stored in one folder through ImageMagick

I have different types of pics in one folder. Some of them are GIF, PNG, JPG. I want to resize all the pics stored in that folder to a definite size, say 100*100 in JPG format from command line.

Steps: Browse to the folder where all pics are stored. My all pics are in "Pics" folder located in C drive.
So, I ran the command prompt and browse to
"C:\Pics>"

There ran the command,
C:\Pics>convert *.* -resize 100x100! small.jpg
Now, what this command will do? How it will create different images? Will it overwrite the images as the destination name is same (small.jpg).

This command will pick all the images one by one, whatever be the format and resize them and store them with name small-0.jpg, small-1.jpg, small-2.jpg and such, it will take care of the name itself and will  not overwrite the image. Great ! isn't it.

Various options available in ImageMagick

I explained how to resize the image using convert command from command line. This is only one of the options in ImageMagick. There are lots more. Here is the complete list of options available in ImageMagick that we can use from command line:

convert [options ...] file [ [options ...] file ...] [options ...] file

Image Settings:
  -adjoin                                    join images into a single multi-image file
  -affine matrix                           affine transform matrix
  -alpha option                           activate, deactivate, reset, or set the alpha channel
  -antialias                                  remove pixel-aliasing
  -authenticate password            decipher image with this password
  -attenuate value                        lessen (or intensify) when adding noise to an image
  -background color                   background color
  -bias value                               add bias when convolving an image
  -black-point-compensation      use black point compensation
  -blue-primary point                  chromaticity blue primary point
  -bordercolor color                   border color
  -caption string                          assign a caption to an image
  -channel type                          apply option to select image channels
  -colors value                           preferred number of colors in the image
  -colorspace type                     alternate image colorspace
  -comment string                      annotate image with comment
  -compose operator                 set image composite operator
  -compress type                       type of pixel compression when writing the image
  -define format:option               define one or more image format options
  -delay value                            display the next image after pausing
  -density geometry                   horizontal and vertical density of the image
  -depth value                           image depth
  -direction type                        render text right-to-left or left-to-right
  -display server                       get image or font from this X server
  -dispose method                    layer disposal method
  -dither method                       apply error diffusion to image
  -encoding type                       text encoding type
  -endian type                          endianness (MSB or LSB) of the image
  -family name                         render text with this font family
  -fill color                              color to use when filling a graphic primitive
  -filter type                            use this filter when resizing an image
  -font name                           render text with this font
  -format "string"                    output formatted image characteristics
  -fuzz distance                      colors within this distance are considered equal
  -gravity type                        horizontal and vertical text placement
  -green-primary point           chromaticity green primary point
  -intent type                          type of rendering intent when managing the image color
  -interlace type                     type of image interlacing scheme
  -interline-spacing value        set the space between two text lines
  -interpolate method             pixel color interpolation method
  -interword-spacing value     set the space between two words
  -kerning value                    set the space between two letters
  -label string                        assign a label to an image
  -limit type value                  pixel cache resource limit
  -loop iterations                   add Netscape loop extension to your GIF animation
  -mask filename                   associate a mask with the image
  -mattecolor color                frame color
  -monitor                             monitor progress
  -orient type                        image orientation
  -page geometry                 size and location of an image canvas (setting)
  -ping                                 efficiently determine image attributes
  -pointsize value                 font point size
  -precision value                maximum number of significant digits to print
  -preview type                   image preview type
  -quality value                    JPEG/MIFF/PNG compression level
  -quiet                               suppress all warning messages
  -red-primary point            chromaticity red primary point
  -regard-warnings              pay attention to warning messages
  -remap filename               transform image colors to match this set of colors
  -respect-parentheses        settings remain in effect until parenthesis boundary
  -sampling-factor geometry                   horizontal and vertical sampling factor
  -scene value                     image scene number
  -seed value                      seed a new sequence of pseudo-random numbers
  -size geometry                  width and height of image
  -stretch type                    render text with this font stretch
  -stroke color                   graphic primitive stroke color
  -strokewidth value           graphic primitive stroke width
  -style type                       render text with this font style
  -taint                               image as ineligible for bi-modal delegate
  -texture filename              name of texture to tile onto the image background
  -tile-offset geometry         tile offset
  -treedepth value               color tree depth
  -transparent-color color    transparent color
  -undercolor color            annotation bounding box color
  -units type                       the units of image resolution
  -verbose                         print detailed information about the image
  -view                              FlashPix viewing transforms
  -virtual-pixel method       virtual pixel access method
  -weight type                   render text with this font weight
  -white-point point           chromaticity white point

Image Operators:
  -adaptive-blur geometry                   adaptively blur pixels; decrease effect near edges
  -adaptive-resize geometry                adaptively resize image using 'mesh' interpolation
  -adaptive-sharpen geometry            adaptively sharpen pixels; increase effect near edges
  -alpha option                                      on, activate, off, deactivate, set, opaque, copy
                                                                transparent, extract, background, or shape
  -annotate geometry text                    annotate the image with text
  -auto-gamma                                       automagically adjust gamma level of image
  -auto-level                                           automagically adjust color levels of image
  -auto-orient                                         automagically orient (rotate) image
  -bench iterations                                measure performance
  -black-threshold value                      force all pixels below the threshold into black
  -blue-shift factor                                simulate a scene at nighttime in the moonlight
  -blur geometry                                    reduce image noise and reduce detail levels
  -border geometry                               surround image with a border of color
  -bordercolor color                              border color
  -brightness-contrast geometry        improve brightness / contrast of the image
  -cdl filename                                        color correct with a color decision list
  -charcoal radius                                  simulate a charcoal drawing
  -chop geometry                                  remove pixels from the image interior
  -clamp                                                  restrict pixel range from 0 to the quantum depth
  -clip                                                      clip along the first path from the 8BIM profile
  -clip-mask filename                             associate a clip mask with the image
  -clip-path id                                         clip along a named path from the 8BIM profile
  -colorize value                                     colorize the image with the fill color
  -color-matrix matrix                             apply color correction to the image
  -contrast                                              enhance or reduce the image contrast
  -contrast-stretch geometry               improve contrast by `stretching' the intensity range
  -convolve coefficients                       apply a convolution kernel to the image
  -cycle amount                                      cycle the image colormap
  -decipher filename                              convert cipher pixels to plain pixels
  -deskew threshold                              straighten an image
  -despeckle                                            reduce the speckles within an image
  -distort method args                           distort images according to given method ad args
  -draw string                                          annotate the image with a graphic primitive
  -edge radius                                         apply a filter to detect edges in the image
  -encipher filename                               convert plain pixels to cipher pixels
  -emboss radius                                    emboss an image
  -enhance                                               apply a digital filter to enhance a noisy image
  -equalize                                               perform histogram equalization to an image
  -evaluate operator value                    evaluate an arithmetic, relational, or logical expression
  -extent geometry                                 set the image size
  -extract geometry                                extract area from image
  -fft                                                          implements the discrete Fourier transform (DFT)
  -flip                                                        flip image vertically
  -floodfill geometry color                    floodfill the image with color
  -flop                                                      flop image horizontally
  -frame geometry                                  surround image with an ornamental border
  -function name parameters                apply function over image values
  -gamma value                                       level of gamma correction
  -gaussian-blur geometry                    reduce image noise and reduce detail levels
  -geometry geometry                           preferred size or location of the image
  -identify                                                identify the format and characteristics of the image
  -ift                                                          implements the inverse discrete Fourier transform (DFT)
  -implode amount                                 implode image pixels about the center
  -lat geometry                                       local adaptive thresholding
  -layers method                                    optimize, merge,  or compare image layers
  -level value                                          adjust the level of image contrast
  -level-colors color,color                    level image with the given colors
  -linear-stretch geometry                    improve contrast by `stretching with saturation'
  -liquid-rescale geometry                    rescale image with seam-carving
  -median radius                                    apply a median filter to the image
  -modulate value                                  vary the brightness, saturation, and hue
  -monochrome                                      transform image to black and white
  -morphology method kernel             apply a morphology method to the image
  -motion-blur geometry                      simulate motion blur
  -negate                                                replace every pixel with its complementary color
  -noise radius                                      add or reduce noise in an image
  -normalize                                           transform image to span the full range of colors
  -opaque color                                    change this color to the fill color
  -ordered-dither NxN                         add a noise pattern to the image with specific amplitudes
  -paint radius                                      simulate an oil painting
  -polaroid angle                                  simulate a Polaroid picture
  -posterize levels                                reduce the image to a limited number of color levels
  -profile filename                                add, delete, or apply an image profile
  -quantize colorspace                        reduce colors in this colorspace
  -radial-blur angle                              radial blur the image
  -raise value                                        lighten/darken image edges to create a 3-D effect
  -random-threshold low,high           random threshold the image
  -region geometry                              apply options to a portion of the image
  -render                                                render vector graphics
  -repage geometry                             size and location of an image canvas
  -resample geometry                         change the resolution of an image
  -resize geometry                               resize the image
  -roll geometry                                   roll an image vertically or horizontally
  -rotate degrees                                 apply Paeth rotation to the image
  -sample geometry                            scale image with pixel sampling
  -scale geometry                               scale the image
  -segment values                              segment an image
  -selective-blur geometry                selectively blur pixels within a contrast threshold
  -sepia-tone threshold                     simulate a sepia-toned photo
  -set property value                         set an image property
  -shade degrees                                shade the image using a distant light source
  -shadow geometry                          simulate an image shadow
  -sharpen geometry                          sharpen the image
  -shave geometry                              shave pixels from the image edges
  -shear geometry                               slide one edge of the image along the X or Y axis
  -sigmoidal-contrast geometry        increase the contrast without saturating highlights or shadows
  -sketch geometry                             simulate a pencil sketch
  -solarize threshold                           negate all pixels above the threshold level
  -sparse-color method args              fill in a image based on a few color points
  -splice geometry                              splice the background color into the image
  -spread radius                                  displace image pixels by a random amount
  -strip                                                  strip image of all profiles and comments
  -swirl degrees                                   swirl image pixels about the center
  -threshold value                               threshold the image
  -thumbnail geometry                       create a thumbnail of the image
  -tile filename                                     tile image when filling a graphic primitive
  -tint value                                         tint the image with the fill color
  -transform                                         affine transform image
  -transparent color                            make this color transparent within the image
  -transpose                                         flip image vertically and rotate 90 degrees
  -transverse                                        flop image horizontally and rotate 270 degrees
  -trim                                                    trim image edges
  -type type                                          image type
  -unique-colors                                  discard all but one of any pixel color
  -unsharp geometry                          sharpen the image
  -vignette geometry                          soften the edges of the image in vignette style
  -wave geometry                                alter an image along a sine wave
  -white-threshold value                    force all pixels above the threshold into white

Image Sequence Operators:
  -append                                      append an image sequence top to bottom
  -clut                                             apply a color lookup table to the image
  -coalesce                                     merge a sequence of images
  -combine                                     combine a sequence of images
  -composite                                  composite image
  -crop geometry                           cut out a rectangular region of the image
  -deconstruct                               break down an image sequence into constituent parts
  -evaluate-sequence operator        evaluate an arithmetic, relational, or logical expression
  -flatten                                        flatten a sequence of images
  -fx expression                            apply mathematical expression to an image channel(s)
  -hald-clut                                   apply a Hald color lookup table to the image
  -morph value                             morph an image sequence
  -mosaic                                       create a mosaic from an image sequence
  -print string                                interpret string and print to console
  -process arguments                  process the image with a custom image filter
  -reverse                                       reverse image sequence
  -separate                                     separate an image channel into a grayscale image
  -write filename                            write images to this file

Image Stack Operators:
  -clone index                                  clone an image
  -delete index                                 delete the image from the image sequence
  -insert index                                  insert last image into the image sequence
  -swap indexes                              swap two images in the image sequence

Miscellaneous Options:
  -debug events                              display copious debugging information
  -help                                              print program options
  -list type                                       print a list of supported option arguments
  -log format                                   format of debugging information
  -version                                        print version information


By default, the image format of `file' is determined by its magic number.  To specify a particular image format, precede the filename with an image format name and a colon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps).  Specify 'file' as '-' for standard input or output.

How to resize image of the exact size from command line with help of ImageMagick

ImageMagick is a free software suite to create, edit, and compose bitmap images. It can read, convert and write images in a large variety of formats. Images can be cropped, colors can be changed, various effects can be applied, images can be rotated and combined, and text, lines, polygons, ellipses and Bézier curves can be added to images and stretched and rotated. In this post, I will show you how to use some of the basic commands from command line.

Below is an image with dimension 500*288

To resize it to smaller size of Dimension 100*100, you can browse to the folder where image is located, my image location is C drive, so I opened command prompt (working on Windows platform) and browse to C drive then use the command:
C:\>convert magic-tree.jpg -resize 100x100 small.jpg
 


magic-tree.jpg is my original image which I want to resize.
small.jpg is my final image created after resizing

But, you will find that the Dimension is not 100*100, instead it is 100*58. This is because its maintaining aspect ratio.

To ignore aspect ratio and to resize it to exact size, you have to use Ignore Aspect Ratio ('!' flag)
 


C:\>convert magic-tree.jpg -resize 100x100! small.jpg.

Similarly, you can resize the image of any size and any fomat like jpg, png etc.
RoR Guide & Solutions: Various options available in ImageMagick

What is the difference between ImageMagick and RMagick

ImageMagick is a software suite to create, edit, compose, or convert bitmap images, resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves. It can read and write images in different types of formats including GIF, JPEG,PDF, PNG, TIFF and many more.

Its functionality can be utilized from the command line or you can use the features from programs like: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), L-Magick (Lisp), NMagick (Neko/haXe), MagickNet (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK).



RMagick is a binding from Ruby to the ImageMagick image manipulation library. RMagick is a complete interface to ImageMagick. RMagick 1 and RMagick 2 are the two RMagick versions. RMagick 2 is the future of RMagick which works with the latest Ruby version