Skip to content

Commit 5e4ddf8

Browse files
committed
init
0 parents  commit 5e4ddf8

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

.github/workflows/image.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: build docker image
2+
on:
3+
push:
4+
jobs:
5+
push_to_registry:
6+
name: Push Docker image to Docker Hub
7+
runs-on: ubuntu-latest
8+
9+
permissions:
10+
packages: write
11+
contents: read
12+
13+
steps:
14+
- name: Check out the repo
15+
uses: actions/checkout@v4
16+
17+
- name: Login to GitHub Container Registry
18+
uses: docker/login-action@v3
19+
with:
20+
registry: ghcr.io
21+
username: ${{ github.actor }}
22+
password: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Build and push Docker image
25+
uses: docker/build-push-action@v5
26+
with:
27+
context: .
28+
file: ./Dockerfile
29+
push: true
30+
build-args: |
31+
"VERSION=${{ github.sha }}"
32+
tags: ghcr.io/linalinn/kicad:nightly

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM kicad/kicad:nightly
2+
3+
RUN sudo apt update -y && \
4+
sudo apt install -y ffmpeg
5+
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
8+
ARG VERSION=no-version
9+
10+
ENV VERSION=$VERSION
11+
12+
COPY *.sh /usr/bin/

action.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# action.yml
2+
name: 'kicad render pcb'
3+
description: 'Render KiCad PCBs top, bottom optionally render and gif or mp4 of the PCB rotating'
4+
inputs:
5+
pcb_file: # id of input
6+
description: 'Path to your .kicad_pcb'
7+
required: true
8+
output_path:
9+
description: 'path to where top.png and bottom.png should be created'
10+
required: true
11+
backgroud:
12+
description: 'Image background. Options: transparent, opaque. Default: transparent for PNG, opaque for JPEG'
13+
required: false
14+
animation:
15+
description: 'If an animation of the PCB rotating should be rendered (backgroud dose not apply)'
16+
required: false
17+
runs:
18+
using: 'docker'
19+
image: 'ghcr.io/linalinn/kicad-render:nightly'
20+
args:
21+
- if [ -n "$INPUT_ANIMATION") ]; then render-pcb.sh -f $INPUT_PCB_FILE -o $INPUT_OUTPUT_PATH -b INPUT_BACKGROUND -a $INPUT_ANIMATION else render-pcb.sh -f $INPUT_PCB_FILE -o $INPUT_OUTPUT_PATH -b INPUT_BACKGROUND if
22+

kicad_animation.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
#
4+
# Original by: arturo182
5+
# gist: https://gist.github.com/arturo182/57ab066e6a4a36ee22979063e4d5cce1
6+
#
7+
FORMAT="$1"
8+
OUTPUT_DIR="${3:-/pwd}"
9+
FRAME_DIR="/tmp/render"
10+
INPUT_FILE="$2"
11+
ZOOM=0.7
12+
WIDTH=1080
13+
HEIGHT=1080
14+
ROTATE_X=0
15+
ROTATE_Z=45
16+
ROTATION=360 # Total rotation angle
17+
STEP=3 # Rotation step in degrees
18+
FRAMERATE=30 # Framerate for the final video
19+
20+
KICAD_CLI=$(which kicad-cli || which kicad-cli-nightly)
21+
22+
mkdir -p $OUTPUT_DIR
23+
mkdir -p $FRAME_DIR
24+
25+
let FRAMES=ROTATION/STEP
26+
for ((i = 0; i < FRAMES; i++)); do
27+
ROTATE_Y=-$(($i * STEP))
28+
OUTPUT_PATH="$FRAME_DIR/frame$i.png"
29+
echo "Rendering frame $i ($ROTATE_Y degrees) to $OUTPUT_PATH"
30+
$KICAD_CLI pcb render --rotate "$ROTATE_X,$ROTATE_Y,$ROTATE_Z" --zoom $ZOOM -w $WIDTH -h $HEIGHT --background opaque -o $OUTPUT_PATH $INPUT_FILE > /dev/null
31+
done
32+
33+
# Combine frames into an MP4 with the specified framerate
34+
if [[ $FORMAT == "mp4" ]]; then
35+
echo "Combining frames into an MP4..."
36+
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" -c:v libx264 -r 30 -pix_fmt yuv420p "$OUTPUT_DIR/rotating.mp4"
37+
echo "MP4 created successfully."
38+
elif [[ $FORMAT == "gif" ]]; then
39+
echo "Combining frames into an GIF..."
40+
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" "$OUTPUT_DIR/rotating.gif"
41+
echo "GIF created successfully."
42+
else
43+
# TODO: this should be vaildated before rendering anything
44+
echo first argument must be mp4 or gif
45+
fi

render-pcb.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
help() {
4+
echo "Convert .kicad_pcb file to front and back image and optionaly render an animation"
5+
echo
6+
echo "Syntax: render-pcb.sh [-f|o|a|h]"
7+
echo "options:"
8+
echo "f Path to .kicad_pcb file"
9+
echo "b Image background. Options: transparent, opaque. Default: transparent for PNG, opaque for JPEG"
10+
echo "o Directory where the images and optinally the animation should be written to."
11+
echo "a Render animation and select animation output format (mp4 or gif)."
12+
echo "v Print protgram version"
13+
echo "h Print this Help."
14+
echo
15+
exit
16+
}
17+
18+
output_path="/pwd"
19+
background="transparent"
20+
21+
while getopts :f:o:a:hv option
22+
do
23+
case "${option}" in
24+
f) kicad_pcb=${OPTARG};;
25+
o) output_path=${OPTARG};;
26+
a) animation=${OPTARG};;
27+
b) background=${OPTARG};;
28+
h) help;;
29+
v) echo "IMAGE version: ${VERSION:-none}" && exit;;
30+
\?)
31+
echo "Error: Invalid option"
32+
exit;
33+
esac
34+
done
35+
36+
if [[ -z "$kicad_pcb" ]]; then
37+
help
38+
fi
39+
40+
if [[ -n "$animation" ]]; then
41+
if [ "$animation" != "gif" ] -a [[ "$animation" != "mp4" ]]; then
42+
help
43+
fi
44+
fi
45+
46+
47+
48+
KICAD_CLI=$(which kicad-cli || which kicad-cli-nightly)
49+
50+
echo $output_path
51+
52+
mkdir -p $output_path
53+
echo "rendering top"
54+
$KICAD_CLI pcb render --side top --background $background -o $output_path/top.png $kicad_pcb > /dev/null
55+
56+
echo "rendering bottom"
57+
$KICAD_CLI pcb render --side bottom --background $background -o $output_path/bottom.png $kicad_pcb > /dev/null
58+
59+
if [[ -n "$animation" ]]; then
60+
echo "rendering animation"
61+
kicad_animation.sh $animation $kicad_pcb $output_path
62+
fi
63+
64+
ls $output_path

0 commit comments

Comments
 (0)