Man*_*ava 4 php ruby-on-rails rmagick
我需要从imagemagick/rmagick库创建一个图像,我该怎么做?就像在php中一样,用GD库完成.
<?php
header ("Content-type: image/png");
$handle = ImageCreate (130, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 0, 0);
ImagePng ($handle);
?>
Run Code Online (Sandbox Code Playgroud)
在输入中,我给出了图像颜色,区域标签的图像坐标,这样的想法?
您需要ImageMagick在您的系统和rmagickgem中安装,然后:
image = Magick::Image.new(130, 50)
image.background_color = 'red'
image.write('someimage.png')
Run Code Online (Sandbox Code Playgroud)
确保您使用PNG支持编译ImageMagick.
要发送您的图像,您可以做下一件事:
send_data image, :type => 'image/png', :disposition => 'inline'
Run Code Online (Sandbox Code Playgroud)
然后,除非要缓存图像,否则无需保存图像.