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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPM or BMP from memory / IO #69

Closed
jpstroop opened this issue Oct 7, 2015 · 9 comments
Closed

PPM or BMP from memory / IO #69

jpstroop opened this issue Oct 7, 2015 · 9 comments

Comments

@jpstroop
Copy link

jpstroop commented Oct 7, 2015

Related to #38 (and following on the solicitation in this comment 馃槈 ) I have scenario where it would be helpful to do the same with either ppm or bmp images. Would this be feasible?

@jcupitt
Copy link
Member

jcupitt commented Oct 7, 2015

PPM wouldn't be too hard: vips has its own PPM reader, it would just need adapting to take a memory source.

vips8 has vips_magickload_buffer(), it would need wrapping up as a vips7 operation and then adding to ruby-vips.

Even better would be to get the new vips8 Ruby binding working, which has all this stuff already :-( This has hit a series of horrible roadblocks.

@jpstroop
Copy link
Author

jpstroop commented Oct 7, 2015

Thanks for your quick response! I'm afraid I wouldn't know where or how to start if I were to take this on--anything below the Ruby level is probably out of my league. If there is pattern somewhere I could look at, maybe I could take a crack...

jcupitt added a commit to libvips/libvips that referenced this issue Oct 7, 2015
@jcupitt
Copy link
Member

jcupitt commented Oct 7, 2015

I've had a quick hack. I'll add patches here as they come in.

It looks like the ppm reader/writer is very wedded to reading and writing files, it would need to be reworked quite a bit to be able to read and write memory as well. I'll have a think.

I've added im_bufmagick2vips() to the vips7 API, it should now be easy to add to ruby-vips.

@jcupitt
Copy link
Member

jcupitt commented Oct 7, 2015

Probably the best solution would be to fix up the load-from-stream branch and merge that, then rewrite the ppm loader to use the stream API.

We should take a look at libgsf as well, perhaps that would be better than load-from-stream.

@jpstroop
Copy link
Author

jpstroop commented Oct 8, 2015

Wow, thanks! Please let me know if there's anything I can do to help.

Speaking of libgsf (though this probably belongs in a separate issue) when trying to install this gem on a fresh Ubuntu 15.04 system, in order to get it to build I had to do:

$ sudo apt-get install libvips-dev
$ sudo apt-get install libgsf-1-dev # i.e. doesn't come in as a dependency of libvips
$ export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH # pkg-config couldn't find vips
$ gem install ruby-vips

jcupitt added a commit that referenced this issue Oct 15, 2015
try:

irb(main):007:0> png_data = IO.read "k2.png"
irb(main):007:0> require 'vips'
irb(main):007:0> reader = VIPS::MagickReader.new png_data
irb(main):007:0> im = reader.read_buffer
irb(main):007:0> im.x_size
=> 1450

see:

#69
@jcupitt
Copy link
Member

jcupitt commented Oct 16, 2015

It seems to be passing Travis now. You can do stuff like:

irb(main):007:0> png_data = IO.read "k2.png"
irb(main):007:0> require 'vips'
irb(main):007:0> reader = VIPS::MagickReader.new png_data
irb(main):007:0> im = reader.read_buffer
irb(main):007:0> im.x_size
=> 1450

It should handle ppm and bmp images too.

This is loading via libMagick, which is not quick. You may find going via a file and using the vips ppm loader is quicker. It'll certainly use less memory (of course).

I've not pushed this change out as a new version of the gem yet, I'll do a bit more testing (though it now passes the test suite cleanly). You'll also need to build vips from git master, which is annoying.

The new ruby-vips8 binding handles this much better, but needs some work still, sigh.

@jpstroop
Copy link
Author

馃憤 Thanks! I should have time to test over the weekend or early next week.

@jcupitt
Copy link
Member

jcupitt commented Jan 18, 2016

There's a new ruby-vips gem with this feature in. Please open a new issue if there are any problems.

@jcupitt jcupitt closed this as completed Jan 18, 2016
@jpstroop
Copy link
Author

Wow, great! I was just thinking that I need to get back to this.

oleksandrbyk added a commit to oleksandrbyk/olek-ruby-vips that referenced this issue Feb 6, 2019
try:

irb(main):007:0> png_data = IO.read "k2.png"
irb(main):007:0> require 'vips'
irb(main):007:0> reader = VIPS::MagickReader.new png_data
irb(main):007:0> im = reader.read_buffer
irb(main):007:0> im.x_size
=> 1450

see:

libvips/ruby-vips#69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants