Last active
January 23, 2019 22:37
-
-
Save iurisegtovich/bb29f6ca09a6a6eb8631feecf4c4007f to your computer and use it in GitHub Desktop.
a python script to convert a figure assembled in libre office impress to a as-high-as-desired quality png and tiff for publication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# currently expect the odp to have only 1 slide | |
# eventually can add the which-slide option as an arg defaulting to 1st | |
# maybe create external python to loop this one across more files or slides of one file | |
import argparse | |
parser = argparse.ArgumentParser(description='Process some fig.') | |
parser.add_argument('--filename',dest='fname', metavar='fname', type=str, nargs='+', | |
help='relative filename', default='fig') | |
parser.add_argument('--dpi',dest='dpi', metavar='dpi', type=int, nargs='+', | |
help='resolution in dpi', default=1000) | |
parser.add_argument('--width',dest='width', metavar='width', type=int, nargs='+', | |
help='width in mm',default=85) | |
args = parser.parse_args() | |
print(args) | |
from subprocess import call, check_output, check_call | |
print('Calling libreoffice') | |
cmdlist=['libreoffice','--headless', '--convert-to', 'eps', args.fname+'.odp'] | |
print(" ".join(cmdlist)) | |
check_call(cmdlist) | |
inches=float(args.width)/25.4 | |
print('args.dpi:', args.dpi) | |
npixel=int(float(args.dpi[0])*inches) | |
print('npixel:',npixel) | |
print('Calling inkscape') | |
cmdlist=['inkscape', '-z', '-e', args.fname+'.png', '-w', str(npixel), args.fname+'.eps'] | |
print(" ".join(cmdlist)) | |
check_call(cmdlist) | |
print('Calling imagemagick') | |
cmdlist=['convert', args.fname+'.png', args.fname+'.tiff'] | |
print(" ".join(cmdlist)) | |
check_call(cmdlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment