<< More Tutorials
How to convert an image to JPG, GIF, PNG, TIF or WebP in Ruby using rethumb?
To convert an image to JPG, GIF, PNG, TIF or WebP in Ruby use the following code:
require 'net/http'
# First apply a square operation, then convert to PNG format.
param_operation1 = "square"
param_value1 = 100
param_operation2 = "format"
param_value2 = "png" # Other formats available: jpg, gif, tiff and webp.
image_url = "http://images.rethumb.com/image_coimbra_600x300.jpg"
image_filename = "resized-image.jpg"
Net::HTTP.start("api.rethumb.com") do |http|
resp = http.get("/v1/#{param_operation1}/#{param_value1}/#{param_operation2}/#{param_value2}/#{image_url}")
open(image_filename, "wb") do |file|
file.write(resp.body)
end
end
Start using this example now
Use the following commands to get started:
$ git clone https://github.com/rethumb/rethumb-ruby-examples.git
$ cd rethumb-ruby-examples
$ ruby format.rb
More examples using Ruby
How to use rethumb in Ruby?
How to resize an image by width in Ruby using rethumb?
How to resize an image by height in Ruby using rethumb?
How to resize an image by width and height in Ruby using rethumb?
How to create a square thumbnail from an image in Ruby using rethumb?
How to read Exif data in json format from an image in Ruby using rethumb?
How to make an image responsive in Ruby using rethumb?
How to read GPS coordinates from an image in Ruby using rethumb?
How to convert an image to JPG, GIF, PNG, TIF or WebP in Ruby using rethumb?
How to resize an image to cover any dimensions in Ruby using rethumb?