Skip to content

CLI commands

SGC Automated App Input Checklist

Before importing

  • Check all H1/H2 combos (Only lessons should have an H1 before the H2 title [not Appendices, Biblio etc])
  • Run VBA script to convert textboxes to footnotes (ConvertTextBox2Footnote)
  • Convert doc to HTML (do NOT use the -s switch for pandoc)
    pandoc input.docx -o output.html --wrap=none
    
  • Import to SGC admin course panel

After importing

  • Add course description, title, etc
  • Add images
  • Add Appendix, Bibliography, etc
  • Add review questions

Compress PDF files

Compress a PDF file to save bandwidth (run in Ubuntu 22.04)
(Uses optimize level "2" because 3 creates artifacts/boxes around transparent images in Apple Safari)

ocrmypdf --tesseract-timeout=0 --optimize 2 --skip-text --output-type pdf input.pdf output.pdf

OCR PDF files for Telugu

Run tesseract (via ocrmypdf) on a PDF file and also output a plaintext file:

ocrmypdf --optimize 3 --force-ocr --sidecar output.txt ML-Telugu.pdf ML-Telugu-out2.pdf -l tel

Install jbig2 codec: https://launchpad.net/~alex-p/+archive/ubuntu/jbig2enc

Convert PDF files to JPG thumbnails

magick mogrify -density 300 -colorspace sRGB -format jpg -path thumbnails -resize "647x647>" -alpha remove -background white *.pdf[0]

Note

  • Manually create the 'thumbnails' dir first, otherwise it won't put the thumbnails there.
  • We're resizing to 647px on the long end. The > at the end of the resize command is what keeps the aspect ratio right.
  • The [0] at the end of the pdf filename is what selects just the first page of the PDF (e.g. if we're creating JPG thumbnails of course cover PDFs.)
  • The -alpha remove -background white is for certain PDFs that apparently had some transparency applied and were coming out with black backgrounds.

Convert PNG files to optimized JPG

magick input.png -quality 80 -define jpeg:optimize-coding=true output.jpg

Or in a recursive batch file:

png_to_jpg.bat
@echo off
setlocal enabledelayedexpansion

for /r %%F in (*.png) do (
   magick "%%F" -quality 80 -define jpeg:optimize-coding=true "%%~dpnF.jpg"
   del "%%F"
)

Convert JPG files to B&W

magick mogrify -colorspace Gray *.jpg

Convert color JPG files to SGC teal tint

Create a folder called converted first.

mkdir converted
for %f in (*.jpg) do magick "%f" -grayscale Rec601Luminance -fill "#4693a5" -colorize 55 -level 10%,70% "converted\%f

Crop Tiles from Images

Crop tiles from images (e.g. for BED bridge diagram Publisher files)

  • Install imagemagick if it's not installed already.
  • Save the full size JPG from Publisher.
  • Go the folder where the JPG is (in File Explorer) and right-click in a blank spot, then click "Open in Terminal"
  • Run the command below:
magick "Bridge diagram (publisher).jpg" -crop 6x1@ -scene 1 Bridge_diagram_%d.jpg

The crop6x1@ tells it to crop 6 tiles equally spaced.
The -scene 1 part tells it to start numbering from 1 instead of 0.

Convert SVG to EMF

Using Inkscape, as shown in this answer.

inkscape.exe" --export-type="emf" English.svg

Create a favicon from an SVG file

Create a 32x32 favicon with a transparent background from an SVG file (change the density to change ico resolution).

magick convert -density 15.25 -background transparent favicon.svg favicon-sgc.ico

Use the following command to get different sizes:

magick convert -background transparent favicon.svg -define icon:auto-resize favicon-sgc.ico

Add meaningful metadata to PDF files

Use exiftool to recursively process all PDF files in a folder, adding the filename as the "Title" of the PDF file, and "Shepherds Global Classroom" as the Author and Creator. (The idea came from this exiftools forum post.)

exiftool.exe -P -r -progress -overwrite_original -ext PDF "-Title<Basename" -Author="Shepherds Global Classroom" -Creator="Shepherds Global Classroom" .

Note

You can run exiftool on the server too. Just download the lastest binary from Github (you'll want the amd64-glibc version for Hostinger). Make it executable, then make sure to set a writable temp directory: export TMPDIR=temp before running your command.