浏览代码

Add snakemake rule to autocrop png files

Ryan C. Thompson 5 年之前
父节点
当前提交
dd1295b0ea
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      Snakefile

+ 7 - 1
Snakefile

@@ -198,7 +198,7 @@ rule pdf_extract_page:
     shell: 'pdfseparate -f {wildcards.pagenum:q} -l {wildcards.pagenum:q} {input:q} {output:q}'
 
 rule pdf_crop:
-    '''Crop away margins from a PDF.'''
+    '''Crop away empty margins from a PDF.'''
     input: pdf = 'graphics/{basename,.*(?!CROP).*}.pdf'
     output: pdf = 'graphics/{basename}-CROP.pdf'
     shell: 'pdfcrop --resolution 300 {input:q} {output:q}'
@@ -209,6 +209,12 @@ rule pdf_raster:
     output: png = 'graphics/{basename}-RASTER.png'
     shell: 'pdftoppm -r 600 {input:q} | convert - {output:q}'
 
+rule png_crop:
+    '''Crop away empty margins from a PNG.'''
+    input: pdf = 'graphics/{basename,.*(?!CROP).*}.png'
+    output: pdf = 'graphics/{basename}-CROP.png'
+    shell: 'magick {input:q} -trim {output:q}'
+
 rule R_to_html:
     '''Render an R script as syntax-hilighted HTML.'''
     input: '{dirname}/{basename,[^/]+}.R'