Comments (23)
Hello, I guess the thing that aiohttp is giving you is neither a string or buffer. You'll need to cast it somehow I suppose.
To verify that new_from_buffer
is working, try:
import sys
import pyvips
str = open(sys.argv[1], "rb").read()
image = pyvips.Image.new_from_buffer(str, "")
print "image average is", image.avg()
I see:
john@kiwi:~/try$ ./load_buffer.py ~/pics/k2.png
image average is 102.930070717
from pyvips.
Oh, you are right, thanks a lot! It returns bytes and that not works. Do you have any idea how can I load bytes or BytesIO to pyvips?
from pyvips.
Sorry, no idea! It should be easy to convert to a string or buffer, but I don't know how exactly.
from pyvips.
Okay, no problem! :) You helped a lot, thanks.
from pyvips.
I need to reopen this, because I still couldn't solve the problem.
It seems like, BytesIO has a read() function aswell and it returns bytes just like what the open one does:
>>> type(open("/tmp/test.png", "rb").read())
<class 'bytes'>
>>> type(BytesIO().read())
<class 'bytes'>
But the second one not works still... It gives me: TypeError: initializer for ctype 'int(*)(void *, void *)' must be a pointer to same type, not cdata 'void(*)(void *)'
Because aiohttp's read() function returns a bytes aswell, I even tried to pass that but the result is the same.
from pyvips.
Hi again, post a small, complete program I can run and I'll have a look.
from pyvips.
Sorry, I had been really busy nowadays.
I made a small code that you can access here: pyvips_test.txt
Unfortunately that's a txt since Github doesn't support .py files to upload.
It gives me a TypeError: initializer for ctype 'int(*)(void *, void *)' must be a pointer to same type, not cdata 'void(*)(void *)'
error.
from pyvips.
I think you're supposed to use gist for complete programs. I copy-pasted your code here:
https://gist.github.com/jcupitt/459959dfbbdf00371963d9f9d67af834
I'll have a look.
from pyvips.
Hello again, your code is interesting, I'd not seen the async stuff before.
It seems to work for me. I changed the pyvips part to be:
def invert_pyvips(data_source):
image_bytes = data_source.read()
print("seen {} bytes coming in".format(len(image_bytes)))
image = pyvips.Image.new_from_buffer(image_bytes, "")
image = image * [-1, -1, -1, 1] + [255, 255, 255, 0]
new_image_bytes = image.write_to_buffer(".png")
print("written {} bytes of new PNG data".format(len(new_image_bytes)))
return new_image_bytes
And if I run it I see:
john@yingna ~/try $ python3 try273.py
seen 242509 bytes coming in
written 210637 bytes of new PNG data
<class 'bytes'>
from pyvips.
That's with pyvips 2.1.3, perhaps something has changed there?
from pyvips.
Interesting... It gives me the same error and I have the latest pyvips from pip.
I'll take a deeper look on that when I'll be home.
from pyvips.
Here's my pip list
, if it's any help:
john@yingna ~/try $ python3 try273.py
seen 242509 bytes coming in
written 210637 bytes of new PNG data
<class 'bytes'>
john@yingna ~/try $ pip list
Package Version
----------------------- ---------
aafigure 0.6
aiohttp 3.3.2
apturl 0.5.2
asn1crypto 0.24.0
async-timeout 3.0.0
atomicwrites 1.1.5
attrs 17.4.0
autobahn 17.10.1
Automat 0.6.0
Brlapi 0.6.6
cbor 1.0.0
certifi 2018.1.18
cffi 1.11.5
chardet 3.0.4
chrome-gnome-shell 0.0.0
click 6.7
cloudpickle 0.5.3
colorama 0.3.7
command-not-found 0.3
configparser 3.5.0
constantly 15.1.0
cryptography 2.1.4
cupshelpers 1.0
cycler 0.10.0
Cython 0.26.1
dask 0.18.2
decorator 4.3.0
defer 1.0.6
dipy 0.14.0
distro-info 0.18
docutils 0.14
funcsigs 1.0.2
future 0.16.0
h5py 2.8.0
httplib2 0.9.2
hyperlink 17.3.1
idna 2.6
idna-ssl 1.1.0
incremental 16.10.1
isodate 0.6.0
jedi 0.11.1
Jinja2 2.10
keyring 10.6.0
keyrings.alt 3.0
kiwisolver 1.0.1
language-selector 0.1
launchpadlib 1.10.6
lazr.restfulclient 0.13.5
lazr.uri 1.0.3
lockfile 0.12.2
louis 3.5.0
lxml 4.2.1
lz4 0.10.1
macaroonbakery 1.1.3
Mako 1.0.7
MarkupSafe 1.0
matplotlib 2.2.2
mock 2.0.0
more-itertools 4.2.0
mpi4py 2.0.0
multidict 4.3.1
networkx 2.1
nibabel 2.2.1
nipype 1.0.4
nitime 0.7
numpy 1.14.4
oauth 1.0.1
olefile 0.45.1
packaging 17.1
PAM 0.4.2
pandas 0.23.0
parso 0.1.1
pbr 4.0.4
pdfrw 0.4
pexpect 4.2.1
Pillow 5.1.0
pip 18.0
pkgconfig 1.3.1
pkginfo 1.4.2
pluggy 0.6.0
protobuf 3.0.0
prov 1.5.2
py 1.5.3
py-ubjson 0.8.5
pyasn1 0.4.2
pyasn1-modules 0.2.1
pycairo 1.16.2
pycparser 2.18
pycrypto 2.6.1
pycups 1.9.73
pydot 1.2.4
pydotplus 2.0.2
Pygments 2.2.0
pygobject 3.26.1
pymacaroons 0.13.0
PyNaCl 1.1.2
pyOpenSSL 17.5.0
pyparsing 2.2.0
PyPDF2 1.26.0
pyRFC3339 1.0
pyserial 3.4
pytest 3.6.1
python-apt 1.6.2
python-dateutil 2.7.3
python-debian 0.1.32
python-snappy 0.5
PyTrie 0.2
pytz 2018.3
pyvips 2.1.3
PyWavelets 0.5.2
pyxattr 0.6.0
pyxdg 0.25
PyYAML 3.12
qrcode 5.3
rdflib 4.2.2
reportlab 3.4.0
requests 2.18.4
requests-toolbelt 0.8.0
requests-unixsocket 0.1.5
rson 0.9
scikit-image 0.14.0
scipy 1.1.0
scour 0.36
seaborn 0.8.1
SecretStorage 2.3.1
service-identity 16.0.0
setuptools 39.0.1
simplejson 3.13.2
six 1.11.0
smartypants 1.8.6
structural-dhcp-mriqc 0.8.4a2
structural-dhcp-rst2pdf 0.93.dev0
structural-dhcp-svg2rlg 0.3
system-service 0.3
systemd-python 234
Tenjin 1.1.1
testresources 2.0.1
toolz 0.9.0
tox 3.1.3
tqdm 4.24.0
traits 4.6.0
twine 1.11.0
Twisted 17.9.0
txaio 2.8.1
u-msgpack-python 2.1
ubuntu-drivers-common 0.0.0
ufw 0.35
unattended-upgrades 0.1
urllib3 1.22
usb-creator 0.3.3
virtualenv 16.0.0
wadllib 1.3.2
wheel 0.30.0
wsaccel 0.6.2
xkit 0.0.0
yarl 1.2.6
youtube-dl 2018.3.14
zope.interface 4.3.2
john@yingna ~/try $ python3 --version
Python 3.6.5
from pyvips.
I'm running into this issue. This seems to be caused by libvips
older than 8.6 being used in non-API mode (which, if I understand correctly, means it's using system-installed libvips
rather than self-built module):
Line 223 in e8b3ce1
The signature in the error matches the signature for glib_lib.g_free
:
>>> glib_lib.g_free
<cdata 'void(*)(void *)' 0x7f7f29146b10>
>>> vips_lib.vips_value_set_blob
<cdata 'void(*)(GValue *, int(*)(void *, void *), void *, size_t)' 0x7f7f28804610>
from pyvips.
I'm running into the same issue on my production server (Ubuntu 18.04), but not on my development server (Ubuntu 18.04). Both use the same libvips version (8.4.5) and pyvips version (2.1.8; the Python environments for dev and prod are identical). I can confirm that enabling API_mode will allow images to be created from bytes when this error occurs.
import pyvips
img = 'static/img.png'
with open(img, 'rb') as f:
image = pyvips.Image.new_from_buffer(f.read(), '')
This will work as expected in dev but not in prod, which says "initializer for ctype 'int(*)(void *, void *)' must be a pointer to same type, not cdata 'void(*)(void *)'.
Can anyone think of any reason why one server would work just dandy but not the other? Thank you all very much!
from pyvips.
I think I might have fixed this in git master pyvips. Would anyone be able to test it?
from pyvips.
It's this commit, for reference: 6ed388b
from pyvips.
Thank you! I'll check it out in about 12 hours when I get home from work.
from pyvips.
Looks good! Both environments work as expected. Thank you very much!
EDIT: I believe pyvips.API_mode is being set to True in these cases. While the image does load, some methods (such as thumbnail_image()) are not working. Is that expected?
from pyvips.
Huh, no, I think that should be OK.
What doesn't work? Is there an error message?
from pyvips.
----> 1 i.thumbnail_image(600)
~/coop_env/lib/python3.6/site-packages/pyvips/vimage.py in call_function(*args, **kwargs)
917 @_add_doc(name)
918 def call_function(*args, **kwargs):
--> 919 return pyvips.Operation.call(name, self, *args, **kwargs)
920
921 return call_function
~/coop_env/lib/python3.6/site-packages/pyvips/voperation.py in call(operation_name, *args,
**kwargs)
220 # args, kwargs)
221
--> 222 intro = Introspect.get(operation_name)
223
224 if len(intro.required_input) != len(args):
~/coop_env/lib/python3.6/site-packages/pyvips/voperation.py in get(cls, operation_name)
139 def get(cls, operation_name):
140 if operation_name not in cls._introspect_cache:
--> 141 cls._introspect_cache[operation_name] = Introspect(operation_name)
142
143 return cls._introspect_cache[operation_name]
~/coop_env/lib/python3.6/site-packages/pyvips/voperation.py in __init__(self, operation_name)
36
37 def __init__(self, operation_name):
---> 38 op = Operation.new_from_name(operation_name)
39
40 self.description = op.get_description()
~/coop_env/lib/python3.6/site-packages/pyvips/voperation.py in
new_from_name(operation_name)
179 vop = vips_lib.vips_operation_new(_to_bytes(operation_name))
180 if vop == ffi.NULL:
--> 181 raise Error('no such operation {0}'.format(operation_name))
182 return Operation(vop)
183
Error: no such operation thumbnail_image
VipsOperation: class "thumbnail_image" not found
Is it possible that there's some other Ubuntu package installed that is causing the disparity? Should I attempt a diff between the two to see if there are any differences?
from pyvips.
Ah that's just an old libvips. thumbnail_image
was added in 8.6.
I would not use thumbnail_image
unless you absolutely have to, it's MUCH slower (perhaps more than 10x slower in some cases) than thumbnail
.
from pyvips.
Gotcha! Thank you again for your help!
from pyvips.
No problem, and thanks again for the report.
from pyvips.
Related Issues (20)
- Reading in image a second time breaks on qptiff file HOT 6
- Documentation link to conda package HOT 1
- Create svs file with image pyramid, label and macro in pyvips? HOT 4
- Image merge stitch HOT 2
- `addalpha` has different behaviour compared to C HOT 1
- Error installing pyvips on Mac OS HOT 15
- draw_rect fill error HOT 2
- creating tiles of 16bit multiband (4 band) tiff image leaves black canvas HOT 4
- class "jxlsave" not found HOT 9
- Assertion failed: sp->cinfo.comm.is_decompressor HOT 3
- Help installing pyvips for jupyter HOT 5
- `TIFFFillTile: Read error` when writing a TIFF file on a per-tile basis. HOT 2
- Thumbnail creation taking too long HOT 2
- Unable to save images when certain combinations of them are resize()'d HOT 7
- pyvips stats HOT 1
- How does composite() merge colors? HOT 8
- ICC profiles from file stream in pyvips HOT 5
- Why is error 0x7f? HOT 1
- Can libvips' stack size be modified using pyvips? HOT 6
- Unable to convert multiband image to srgb HOT 9
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 pyvips.