Reputation: 3396
I have a requirement to perform some simple image manipulation in Python, with the constraint that I can't assume the presence of anything but standard Python - no third party modules, not even PIL.
The actual function I need is scaling - preferably something more than simple pixel dropping or keeping, so some interpolation to produce an OK-looking image. As far as I can think, my options are:
I have two questions, really:
Upvotes: 1
Views: 769
Reputation: 102
You can package the pure python pymaging library with your application for only a 40K overhead.
$ git clone https://github.com/ojii/pymaging.git
Cloning into 'pymaging'...
[...]
$ (cd pymaging && zip -r pymaging.zip pymaging/)
adding: pymaging/ (stored 0%)
[...]
$ (echo 'pymaging_zip = """' && base64 pymaging/pymaging.zip && echo '"""') > out.py
$ cat >> out.py <<'EOF'
import tempfile
import os
import sys
import base64
pymaging_tmp_fd, pymaging_tmp_path = tempfile.mkstemp(suffix='.zip')
os.write(pymaging_tmp_fd, base64.b64decode(pymaging_zip))
os.close(pymaging_tmp_fd)
sys.path.append(pymaging_tmp_path)
import pymaging
EOF
$ wc -c out.py
40420 out.py
This packs up the pymaging library into a zip file which is then embedded into your application. It writes the zip file to a temporary file and then uses Python's ability to import libraries from zip files.
You should probably consider cleaning up the temporary file afterwards, especially if this is to be used on Windows.
Upvotes: 2