Skip to content

How to build one binary using with mruby cli

Junichi Kajiwara edited this page Feb 18, 2016 · 3 revisions

How to build one binary using with mruby-cli

git clone git@github.com:kjunichi/mruby-mrmagick.git 
mruby-cli --setup mrmagickapp
cd mrmagickapp
cp ../mruby-mrmagick/docker/* .

Write your main code

edit mrblib/mrmagickapp.rb

for example:

def __main__(argv)
srcImagePath = argv[1]

    srcImg = Mrmagick::ImageList.new(srcImagePath)
    srcImg = srcImg.auto_orient
    srcWidth = srcImg.columns
    srcHeight = srcImg.rows
    if srcWidth > srcHeight
      srcImg = srcImg.crop((srcWidth - srcHeight) / 2, 0, srcHeight, srcHeight)
      srcWidth = srcHeight
    end
    if srcWidth < srcHeight
      srcImg = srcImg.crop(0, (srcHeight - srcWidth) / 2, srcWidth, srcWidth)
      srcHeight = srcWidth
    end
    if srcWidth>512
      srcImg = srcImg.scale(512,512)
      srcWidth = 512
      srcHeight = 512
    end

    destImg = srcImg.rotate(0)
    for i in 1..20
      rot = i * 18
      scale = 1 + (i / 10.5)
      tmpImg = srcImg.scale(scale).rotate(rot)
      width = tmpImg.columns
      height = tmpImg.rows
      tmpImg = tmpImg.crop((width-srcWidth)/2, (height-srcHeight)/2, srcWidth, srcHeight)
      #tmpImg.write(rot.to_s + '.jpg')
      destImg.push tmpImg
    end
    destImg.write('animate.gif')
end

Build

docker-compose run compile

It takes two or three hours...

find  mruby/build |grep bin/mrmagickapp
mruby/build/host/bin/mrmagickapp
mruby/build/i386-apple-darwin14/bin/mrmagickapp
mruby/build/i686-pc-linux-gnu/bin/mrmagickapp
mruby/build/i686-w64-mingw32/bin/mrmagickapp.exe
mruby/build/x86_64-apple-darwin14/bin/mrmagickapp
mruby/build/x86_64-pc-linux-gnu/bin/mrmagickapp
mruby/build/x86_64-w64-mingw32/bin/mrmagickapp.exe