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

Create a new image from scratch #59

Closed
vivien opened this Issue Nov 30, 2011 · 10 comments

Comments

Projects
None yet
8 participants
@vivien
Copy link

vivien commented Nov 30, 2011

Hi,

If I'm not mistaken, it is not possible to create a new image (which doesn't exist on the disk yet) with MiniMagick, while it is possible with the convert tool. It would be useful, especially for canvas and composite. Here's a dirty hack I'm using:

def new_image(width, height, format = "png", bgcolor = "transparent")
  tmp = Tempfile.new(%W[mini_magick_ .#{format}])
  `convert -size #{width}x#{height} xc:#{bgcolor} #{tmp.path}`
  MiniMagick::Image.new(tmp.path, tmp)
end

It would be interesting to add this feature in MiniMagick unless something similar already exists.

Best,
Vivien.

@lhz

This comment has been minimized.

Copy link

lhz commented Feb 2, 2012

I would love this see this feature implemented as well, and not just in the documentation...

image = MiniMagick::Image.create 'jpg', false do |c|
  c.size '1024x1024' # creates image option '-size 1024x1024'
  c.canvas 'black'   # creates image creation operator 'canvas:black'
end

This doesn't work, since what is passed to the block is the Tempfile object, not the image.

@davidmles

This comment has been minimized.

Copy link

davidmles commented Feb 22, 2012

I agree. If it is documented then it should be implemented.

@robertjwhitney

This comment has been minimized.

Copy link
Contributor

robertjwhitney commented Mar 6, 2012

from lib/mini_magick.rb:

# Used to create a new Image object data-copy. Not used to "paint" or that kind of thing.
      #
      # Takes an extension in a block and can be used to build a new Image object. Used
      # by both #open and #read to create a new object! Ensures we have a good tempfile!

@robertjwhitney

This comment has been minimized.

Copy link
Contributor

robertjwhitney commented Mar 13, 2012

Ok, after a bunch of discussion around my pull request, the offending commit, and elsewhere, I think it's pretty much been pretty much agreed upon that this feature is defunct. The code that adds the feature wasn't tested. My above pull request will work for the example, but it relies on tempfile, which it shouldn't. The example will be removed from the documentation to avoid confusion and hopefully a refactor will allow support for some of ImageMagick's command line methods beyond mogrify to enjoy better support in mini_magick.

Anyone interested in participating in a discussion around a possible refactor can participate here: https://gist.github.com/2012377

@novito

This comment has been minimized.

Copy link

novito commented Oct 24, 2013

How this discussion ended? I am trying to create a straight 1024x768 PNG image with white background by doing

collage = MiniMagick::Image.create "png", false do |c|
      c.size "1024x768"
      c.canvas "white"
    end

And it's saying ArgumentError (wrong number of arguments (1 for 0)):

What am I missing here?

@nofxx

This comment has been minimized.

Copy link

nofxx commented Jun 28, 2015

Should this be reopened? I encoutered this issue trying to create an image.
Did like the OP to monkey patch it, but ended up creating a 1px transparent png and loading it when needed. Kinda ugly.

@novito It won't work, it's not meant for that (misleading docs). (2 yrs later)

@janko-m janko-m reopened this Jun 28, 2015

@janko-m

This comment has been minimized.

Copy link
Member

janko-m commented Jun 28, 2015

I've read through the discussion now, but haven't quite understood what should MiniMagick do. Isn't it already possible to create images on disk with ImageMagick itself (if it is, could someone remind me how)? Do you want MiniMagick to provide some convenient API for it?

@mattbearman

This comment has been minimized.

Copy link

mattbearman commented Jul 27, 2015

This can be done using the bare metal, eg:

# Create a white png, 1024 x 768 pixels
MiniMagick::Tool::Convert.new do | new_image |
  new_image.size "1024x768"
  new_image << "image.png"
end

But it would be nice to have a proper API wrapper for it :)

@janko-m

This comment has been minimized.

Copy link
Member

janko-m commented Jul 27, 2015

Since I'm never creating images (I never needed it so far), I'm not exactly sure how the wrapper should look like. I'd gladly take suggestions or, better yet, PRs :)

@janko-m

This comment has been minimized.

Copy link
Member

janko-m commented Aug 1, 2015

I gave it some more thought, and I think this is actually out of scope of MiniMagick. It would make much more sense to have a library on top of MiniMagick for generating images, and keep MiniMagick low-level as it is.

@janko-m janko-m closed this Aug 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment