Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add magick.new and magick.new_image #26

Open
josefnpat opened this issue Oct 15, 2015 · 1 comment
Open

Add magick.new and magick.new_image #26

josefnpat opened this issue Oct 15, 2015 · 1 comment

Comments

@josefnpat
Copy link

So I was attempting to create and edit png images on the fly with magick, but I found that neither the magick.new or the magick.new_image function existed.

Would you like me to take a crack at adding them in a PR? I am not familiar with moon or the busted system.

For anyone looking for a really poor performance workaround using os.execute and imagemagick's convert, you can use this:

__tmp = '/tmp/pico2png.temp.png'
function new_image(w,h)
  os.execute('convert -size '..w.."x"..h..' xc:white '..__tmp)
  local png,err = magick.load_image(__tmp)
  return png,err
end
__points = {}
__count = 0
function set_pixel(x,y,r,g,b)
  table.insert(__points,"fill rgb("..r..","..g..","..b..") point "..x..","..y.." ")
  if __count > 2^12 then
    __flush_pixels()
    __count = 0
  end
  __count = __count + 1
end
function __flush_pixels()
  os.execute("convert -draw '"..table.concat(__points).."' "..__tmp.." "..__tmp)
  __points = {}
end
-- run this before reading information about your image object.
function __post()
  __flush_pixels()
  return magick.load_image(__tmp)
end
@leafo
Copy link
Owner

leafo commented Oct 15, 2015

magick currently doesn't have any drawing functions, so making a new image isn't that useful. I'm not opposed to adding those kinds of functions though.

This library is an FFI binding to ImageMagick. We can easily introduce any function implemented by ImageMagick's C interface. Here are a bunch: http://www.imagemagick.org/api/magick-image.php

You just need to copy the signature of the function into the statement on the top of init.moon and then you can access it: https://github.com/leafo/magick/blob/master/magick/init.moon#L6

I'm not familiar with the internal drawing API, but maybe if you dig around you can find something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants