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

Return result without disk saving? #368

Closed
hiun opened this issue May 19, 2016 · 4 comments
Closed

Return result without disk saving? #368

hiun opened this issue May 19, 2016 · 4 comments

Comments

@hiun
Copy link

hiun commented May 19, 2016

I would do additional manipulation to image (like base64 encoding). It is more efficient to return image in reference format that skips saving image to disk.

Is it possible in current version of minimagick?

@hiun hiun changed the title Return result without saving to disk? Return result without disk savings? May 19, 2016
@hiun hiun changed the title Return result without disk savings? Return result without disk saving? May 19, 2016
@janko
Copy link
Member

janko commented May 19, 2016

Through MiniMagick::Image it's not possible (and I don't think it could be). However, you can do it via the low-level API:

content = MiniMagick::Tool::Convert.new do |convert|
  convert << path
  convert.resize("500x500")
  convert << "-" # stdout
end

base64 = Base64.encode64(content)

You can even read the input file from stdin:

convert = MiniMagick::Tool::Convert.new
convert << "-"
convert.resize("500x500")
convert << "-" # stdout
processed_content = convert.call(stdin: input_content)

@hiun
Copy link
Author

hiun commented May 22, 2016

Thanks for detailed examples! I may could not fully grasp API document before issuing.

@hiun hiun closed this as completed May 22, 2016
@sairam
Copy link

sairam commented Oct 3, 2018

I was able to use this to write as base64

image = MiniMagick::Image.open("https://placehold.it/300x200")
base64 = Base64.encode64(image.to_blob).split("\n").join

@matthewPapke
Copy link

@sairam thank you for that

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

4 participants