Skip to content

Instantly share code, notes, and snippets.

@Yohn
Last active August 25, 2022 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yohn/9c59eb9930d2d7fff49d45f4c53c382a to your computer and use it in GitHub Desktop.
Save Yohn/9c59eb9930d2d7fff49d45f4c53c382a to your computer and use it in GitHub Desktop.
Converting PDF to PNG with ImageMagick using GitHub Actions. Found on SO - https://stackoverflow.com/questions/67060829/github-action-using-imagemagick-create-a-png-and-commit-it-to-the-repo
name: PDF to PNG
on:
push:
branches:
- kaspar
pull_request:
branches:
- kaspar
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install ghostscript
run: sudo apt install ghostscript
- name: Change ImageMagick security policy
run: |
DQT='"'
SRC="rights=${DQT}none${DQT} pattern=${DQT}PDF${DQT}"
RPL="rights=${DQT}read\|write${DQT} pattern=${DQT}PDF${DQT}"
sudo sed -i "s/$SRC/$RPL/" /etc/ImageMagick-6/policy.xml
- name: Convert PDF to PNG
run: convert -density 900 -background white -alpha off Twenty-Seconds-Icons_cv.pdf -quality 90 Twenty-Seconds-Icons_cv.png
- name: Commit PNG
id: commit
run: |
git config --local user.email "action[bot]@github.com"
git config --local user.name "github-actions[bot]"
git add Twenty-Seconds-Icons_cv.png
if [-z "$(git status --porcelain)"]; then
echo "::set-output name=push::false"
else
git commit -m "[bot] updated Twenty-Seconds-Icons_cv.png"
echo "::set-output name=push::true"
fi
shell: bash
- name: Push Commit
if: steps.commit.outputs.push == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.SECRET_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment