Commit 2efcec6
chasinglightning
·
2025-01-05 16:36:43 -0500 EST
parent 57194e3
add phantomjs scripts from server
7 files changed,
+109,
-3
+40,
-0
| ... | ... | @@ -0,0 +1,40 @@ | |
| 1 | + | #FROM - an alpine image or any image that you may use and are facing the issue | |
| 2 | + | FROM node:6-alpine | |
| 3 | + | ||
| 4 | + | # WORKDIR - any workdir that you may use | |
| 5 | + | # RUN some other commands if needed | |
| 6 | + | ||
| 7 | + | # If you also need fonts then add this - Select any fonts from here https://wiki.alpinelinux.org/wiki/Fonts#List_of_fonts_in_Alpine_Linux:~:text=ttf%2Dubuntu%2Dfont%2Dfamily | |
| 8 | + | # Just replace ttf-ubuntu-font-family with fonts that you need | |
| 9 | + | RUN apk --update add ttf-ubuntu-font-family fontconfig && rm -rf /var/cache/apk/* | |
| 10 | + | ||
| 11 | + | RUN apk add imagemagick | |
| 12 | + | ||
| 13 | + | # if ever you need to change phantom js version number in future ENV comes handy as it can be used as a dynamic variable | |
| 14 | + | ENV PHANTOMJS_VERSION=2.1.1 | |
| 15 | + | ||
| 16 | + | RUN apk add --no-cache curl && \ | |
| 17 | + | cd /tmp && curl -Ls https://github.com/topseom/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz | tar xz && \ | |
| 18 | + | cp -R lib lib64 / && \ | |
| 19 | + | cp -R usr/lib/x86_64-linux-gnu /usr/lib && \ | |
| 20 | + | cp -R usr/share /usr/share && \ | |
| 21 | + | cp -R etc/fonts /etc && \ | |
| 22 | + | curl -k -Ls https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar -jxf - &&\ | |
| 23 | + | cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && \ | |
| 24 | + | rm -fR phantomjs-2.1.1-linux-x86_64 && \ | |
| 25 | + | apk del curl | |
| 26 | + | ||
| 27 | + | # RUN any other commands still pending | |
| 28 | + | # ENTRYPOINT | |
| 29 | + | # CMD | |
| 30 | + | ||
| 31 | + | RUN mkdir -p /raster-root \ | |
| 32 | + | && mkdir -p /raster-output | |
| 33 | + | COPY rasterize.js /raster-root/ | |
| 34 | + | WORKDIR /raster-root | |
| 35 | + | ||
| 36 | + | COPY . . | |
| 37 | + | # These line for /entrypoint.sh | |
| 38 | + | COPY entrypoint.sh /entrypoint.sh | |
| 39 | + | RUN chmod +x /entrypoint.sh | |
| 40 | + | entrypoint "/entrypoint.sh" |
| ... | ... | @@ -0,0 +1,7 @@ | |
| 1 | + | ## for optiplex 9020 server | |
| 2 | + | ||
| 3 | + | run with following cron job on the server: | |
| 4 | + | ||
| 5 | + | ```bash | |
| 6 | + | */30 * * * * cd /home/kat/pjs && /usr/bin/docker compose run --rm pjs /home/kat/pjs/entrypoint.sh && /home/kat/pjs/rsync.sh >> /home/kat/pjs/test2.log 2>&1 | |
| 7 | + | ``` |
| ... | ... | @@ -0,0 +1,8 @@ | |
| 1 | + | services: | |
| 2 | + | pjs: | |
| 3 | + | build: . | |
| 4 | + | ports: | |
| 5 | + | - "9283:5000" | |
| 6 | + | command: /bin/sh -c "entrypoint.sh" | |
| 7 | + | volumes: | |
| 8 | + | - /home/kat/pjs/output:/raster-output |
| ... | ... | @@ -0,0 +1,3 @@ | |
| 1 | + | #!/bin.bash | |
| 2 | + | ||
| 3 | + | phantomjs --ignore-ssl-errors=true --ssl-protocol=any --web-security=true /raster-root/rasterize.js http://wttr.in/New_York?0pqT /raster-output/wttr.png && magick /raster-output/wttr.png -crop 460x460+0+0 -transparent black /raster-output/wttr.png |
+50,
-0
| ... | ... | @@ -0,0 +1,50 @@ | |
| 1 | + | "use strict"; | |
| 2 | + | var page = require('webpage').create(), | |
| 3 | + | system = require('system'), | |
| 4 | + | address, output, size, pageWidth, pageHeight; | |
| 5 | + | ||
| 6 | + | if (system.args.length < 3 || system.args.length > 5) { | |
| 7 | + | console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]'); | |
| 8 | + | console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); | |
| 9 | + | console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px'); | |
| 10 | + | console.log(' "800px*600px" window, clipped to 800x600'); | |
| 11 | + | phantom.exit(1); | |
| 12 | + | } else { | |
| 13 | + | address = system.args[1]; | |
| 14 | + | output = system.args[2]; | |
| 15 | + | page.viewportSize = { width: 1024, height: 2000}; | |
| 16 | + | if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") { | |
| 17 | + | size = system.args[3].split('*'); | |
| 18 | + | page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' } | |
| 19 | + | : { format: system.args[3], orientation: 'portrait', margin: '1cm' }; | |
| 20 | + | } else if (system.args.length > 3 && system.args[3].substr(-2) === "px") { | |
| 21 | + | size = system.args[3].split('*'); | |
| 22 | + | if (size.length === 2) { | |
| 23 | + | var pageWidth = parseInt(size[0], 10), | |
| 24 | + | pageHeight = parseInt(size[1], 10); | |
| 25 | + | page.viewportSize = { width: pageWidth, height: pageHeight }; | |
| 26 | + | page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight }; | |
| 27 | + | } else { | |
| 28 | + | console.log("size:", system.args[3]); | |
| 29 | + | var pageWidth = parseInt(system.args[3], 10), | |
| 30 | + | pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any | |
| 31 | + | console.log ("pageHeight:",pageHeight); | |
| 32 | + | page.viewportSize = { width: pageWidth, height: pageHeight }; | |
| 33 | + | } | |
| 34 | + | } | |
| 35 | + | if (system.args.length > 4) { | |
| 36 | + | page.zoomFactor = system.args[4]; | |
| 37 | + | } | |
| 38 | + | page.open(address, function (status) { | |
| 39 | + | if (status !== 'success') { | |
| 40 | + | console.log('Unable to load the address!'); | |
| 41 | + | phantom.exit(1); | |
| 42 | + | } else { | |
| 43 | + | window.setTimeout(function () { | |
| 44 | + | page.render(output); | |
| 45 | + | console.log("Success"); | |
| 46 | + | phantom.exit(); | |
| 47 | + | }, 200); | |
| 48 | + | } | |
| 49 | + | }); | |
| 50 | + | } |
+1,
-0
| ... | ... | @@ -0,0 +1 @@ | |
| 1 | + | rsync -ave 'ssh' /home/kat/pjs/output/wttr.png kat@192.168.1.123:/home/kat/.config/conky |
+0,
-3