人気ブログランキング | 話題のタグを見る

potraceを使ってみる。

調子に乗って、potraceでmimetexをsvg出力してrcairoに使おうとした。
汚い画面になってしまった。
でも、何かに使えるかも?
で、載せときます。
sudo apt-get install potrace
potraceはbmpをsvgに変換します。

#!usr/bin/env ruby

require 'rubygems'
require 'sdl'
require 'rsvg2'

eval = "f(x)=x^5+8x^4+18x^3+4x^2-19x-12"
@svg = `mimetex -s 7 -o -d '#{eval}' | convert - bmp:- | potrace -s`

handle = RSVG::Handle.new_from_data(@svg)
dim = handle.dimensions
@image = Cairo::ImageSurface.new(dim.width, dim.height)
context = Cairo::Context.new(@image)
context.set_source_color(Cairo::Color::WHITE)
context.rectangle(0, 0, @image.width, @image.height)
context.fill
context.render_rsvg_handle(handle)
@surface = SDL::Surface.new_from(@image.data,@image.width,@image.height,32,@image.stride,0,0,0,0)
@surface.saveBMP("/tmp/image")
#@image.write_to_png("/tmp/image")
`display /tmp/image`
by gaziya | 2011-04-27 00:19