I need to create an image from the imagemagick/rmagick library, How should I do that? as in php it was done like below with GD library.
<?php
header ("Content-type: image/png");
$handle = ImageCreate (130, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 0, 0);
ImagePng ($handle);
?>
In input, I have given image color, image co-ordinates of area tag like that..any idea?
You need ImageMagick
installed in your system and rmagick
gem, then:
image = Magick::Image.new(130, 50)
image.background_color = 'red'
image.write('someimage.png')
Make sure, you have ImageMagick compiled with PNG support.
To send your image, you may do next thing:
send_data image, :type => 'image/png', :disposition => 'inline'
Then you don't need to save an image unless you want to cache it.
More information about usage you can find here
Here's what I used to create an inline image on the fly:
@placeholder = Magick::Image.new(@book.width, @book.height)
@placeholder.format = "png"
@placeholder = "data:image/png;base64,#{Base64.encode64 (@placeholder.to_blob)}"
And:
<img src="<%= @placeholder %>" />
It's not pretty, but it works for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With