Comments (7)
Hi, you need the function vips_jpegload_buffer(), unfortunately not available in Python. Hopefully this is something that will be improved when we move to the new Python binding.
The two functions you found are for wrapping memory buffers of uncompressed pixels up as VIPs images. You can use them to move images between PIL and VIPS efficiently, see:
http://www.vips.ecs.soton.ac.uk/index.php?title=Python_Examples
So an option would be to use the PIL loader, then wrap the decompressed image as VIPS.
from libvips.
I thought that might be the case. I only want to do an affine transform on an image in memory. If I need to open the image with PIL, would you recommend just doing the transform in PIL as well?
Thanks for your quick responses.
from libvips.
I think the pros and cons would be:
VIPS would be faster and would be able to produce just parts of the rotated
image on demand, which might be handy. It has much better interpolators
than PIL and can generate pixels in the background, but sadly not from the
current Python binding.
PIL would be simpler to code and simpler to deploy. And have better
documentation!
On Monday, 30 July 2012, Stephan Boyer wrote:
I thought that might be the case. I only want to do an affine transform
on an image in memory. If I need to open the image with PIL, would you
recommend just doing the transform in PIL as well?Thanks for your quick responses.
Reply to this email directly or view it on GitHub:
https://github.com/jcupitt/libvips/issues/23#issuecomment-7362999
from libvips.
Any update on if/when the Python bindings will support jpegload_buffer (as well as gifload_buffer and pngload_buffer)?
from libvips.
Hi @scyclops, yes, the new Python binding was released with version 8 in 2015.
http://jcupitt.github.io/libvips/API/current/using-from-python.html
Use it like this:
$ python
Python 2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170118] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_version('Vips', '8.0')
>>> from gi.repository import Vips
>>> with open("pics/k2.jpg", 'rb') as f:
... str = f.read()
...
>>> image = Vips.Image.new_from_buffer(str, "")
>>> image.avg()
102.80430080369972
The extra ""
argument is for any load options you might want to set as strings.
There it's sniffing the file type from the first few bytes of the string and calling the appropriate loader for you. You can also call the jpeg loader directly:
>>> image = Vips.Image.jpegload_buffer(str)
>>> image.width
1450
>>> image.avg()
102.80430080369972
You can give optional arguments, for example:
>>> image = Vips.Image.jpegload_buffer(str, shrink = 2, access = Vips.Access.SEQUENTIAL)
>>> image.width
725
>>> image.avg()
102.80430080369972
Now it's loading in sequential mode, and at half size. You can give extra args to .new_from_buffer()
as well.
There are quite a few more buffer loaders now:
$ vips -l | grep load_buffer
VipsForeignLoadPdfBuffer (pdfload_buffer), load PDF with libpoppler, priority=0, is_a_buffer, get_flags, get_flags_filename, header, load
VipsForeignLoadSvgBuffer (svgload_buffer), load SVG with rsvg, priority=0, is_a_buffer, get_flags, get_flags_filename, header, load
VipsForeignLoadGifBuffer (gifload_buffer), load GIF with giflib, priority=0, is_a_buffer, get_flags, get_flags_filename, header
VipsForeignLoadPngBuffer (pngload_buffer), load png from buffer, priority=0, is_a_buffer, get_flags, header, load
VipsForeignLoadJpegBuffer (jpegload_buffer), load jpeg from buffer, priority=0, is_a_buffer, get_flags, header, load
VipsForeignLoadWebpBuffer (webpload_buffer), load webp from buffer, priority=-50, is_a_buffer, get_flags, header, load
VipsForeignLoadTiffBuffer (tiffload_buffer), load tiff from buffer, priority=0, is_a_buffer, get_flags, header, load
VipsForeignLoadMagickBuffer (magickload_buffer), load buffer with ImageMagick, priority=-100, is_a_buffer, get_flags, get_flags_filename, header
from libvips.
Great - it looks like I may have been using the old python binding that I installed by running the below on Ubuntu 16.04.
apt-get install python-vipscc
Any clue on how to easily install the new python bindings on Ubuntu 16.04? It looks like running the following on Ubuntu 16.04 installs vips 8.2.2 with the old bindings but the typelib file is nowhere to be found after the install and from gi.repository import Vips always fails. Or is compiling from source the the only way to get the typelib installed?
apt-get install libvips libvips-tools python-vipscc gobject-introspection python-gi --no-install-recommends
from libvips.
Hi, python-vipscc
is the old binding, you don't need to install it, unless you really want to use it.
The typelib is in gir1.2-vips-8.0
. It used to not include the overrides file, unfortunately. I filed a bug, but I don't know if it was fixed for 16.04.
If you are missing the Vips.py overrides, you can download here:
https://github.com/jcupitt/libvips/blob/master/python/packages/gi/overrides/Vips.py
There's a note in the comment at the top saying where to copy the file to.
from libvips.
Related Issues (20)
- Loading images with jpegli fails with "No SOS marker found." HOT 2
- jxlsave fails with "jxlsave: error JxlEncoderSetBasicInfo" for a 32-bit (?) CMYK colour TIFF HOT 2
- Quality handling in WebP near-lossless (and arguably lossless) mode is incorrect HOT 3
- Conversion to PFM gives incorrect output HOT 2
- Improve `tilecache` performance
- JXL Support in Libvips Web Build HOT 3
- vips: unknown action "dzsave", vips-8.15.1 on Gentoo HOT 1
- Row sums from vips_project do not necessarily give the same value like summing img(i,j) along i HOT 2
- Looks like 8.15.2 tag is wrong? HOT 1
- vips 8.15.2 failed to build with latest xcode HOT 11
- HDR AVIF to HEIC (hdr) HOT 4
- Feature request: Support SDR→HDR via RTX HDR (upmapping / inverse tone mapping)
- AVIF with bitdepth 10 or 12 crashes
- Add nclx->icc colour management to heifload HOT 24
- Segmentation fault when performing very large number of operations HOT 1
- Subsample mode not working with jpegli HOT 4
- Add target write to `rawsave` HOT 2
- Cannot link to proper libraries on Windows 11 Pro. HOT 1
- Thumbnail/Resize removes color on Alpine HOT 1
- Add support for fractional tiff values (eg. 10 or 12 bits per pixel) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libvips.