-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add Introduction to MTSAT readers #8
Conversation
I found this tool a while ago /~https://github.com/arve0/ipynbcompress. I had to tweak it a bit, but it's quite nice to reduce the size of the notebook (mostly images). Maybe it should be tested on this ? |
For sure! I will have a look |
Here are the changes I had to make to the ipynbcompress code to make it work: --- a/ipynbcompress/ipynbcompress.py
+++ b/ipynbcompress/ipynbcompress.py
@@ -53,6 +53,10 @@ def compress(filename, output_filename=None, img_width=2048, img_format='png'):
new_size = [int(s*factor+0.5) for s in img.size]
img = img.resize(new_size)
out = BytesIO()
+ if img.mode == 'RGBA':
+ bgimg = Image.new('RGBA', new_size, (255, 255, 255, 255))
+ bgimg.paste(img, mask=img)
+ img = bgimg.convert('RGB')
img.save(out, img_format)
out.seek(0)
mime = 'image/' + img_format
diff --git a/scripts/ipynb-compress b/scripts/ipynb-compress
index 5304001..9c0e2c5 100755
--- a/scripts/ipynb-compress
+++ b/scripts/ipynb-compress
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# encoding: utf-8
-import climate
+#import climate
+import sys
from ipynbcompress import compress
from hurry.filesize import size, verbose
from tempfile import mkstemp
@@ -9,11 +10,7 @@ from shutil import copyfile
from os import close, remove
from sys import exit
-@climate.annotate(
- img_width=('image width', 'option', 'w'),
- img_format=('image compression; png or jpeg', 'option', 'f')
-)
-def main(filename, output_filename=None, img_width=2048, img_format='png'):
+def main(filename, output_filename=None, img_width=2048, img_format='jpg'):
"""Compress images in IPython notebooks.
filename : Notebook to compress. Will take any notebook format.
@@ -60,4 +57,5 @@ def main(filename, output_filename=None, img_width=2048, img_format='png'):
print('ipynb-compress: error: %s file not found' % filename)
if __name__ == '__main__':
- climate.call(main)
+ #climate.call(main)
+ main(sys.argv[1])
diff --git a/setup.py b/setup.py
index 628e07c..afb0a9a 100755
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,7 @@ setup(
'Pillow',
'jsonschema',
'ipython',
- 'climate',
+ #'climate',
'hurry.filesize'
],
license='MIT', |
@mraspaud Perfect, thanks! |
6ccfc45
to
9bfa216
Compare
@mraspaud Ok, done! Compressed the GOES & MTSAT introductions and reduced the image size of the corresponding mosaics. Total size is now 2MB less than the current master. |
Perfect, thanks a lot! |
Add Introduction to MTSAT readers
Add Introduction to MTSAT readers
Belongs to pytroll/satpy#524