From 3a20754ea69a49134fbb0d0626ef6d5c86b2dc59 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 14 Nov 2023 22:29:55 +0100 Subject: [PATCH] Allow printing *bigger* images --- init_printer.sh | 2 +- print_image.sh | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/init_printer.sh b/init_printer.sh index d1472e3..6cbf0c8 100755 --- a/init_printer.sh +++ b/init_printer.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e dev=/dev/usb/lp0 diff --git a/print_image.sh b/print_image.sh index 6ca9e1d..65744b6 100755 --- a/print_image.sh +++ b/print_image.sh @@ -2,23 +2,26 @@ set -e dev=/dev/usb/lp0 -image="$(magick "$1" -resize 512x -dither FloydSteinberg -remap pattern:gray50 pbm:- | base64)" +image="$(magick "$1"'[0]' -resize 512x1662\> -dither FloydSteinberg -remap pattern:gray50 pbm:- | base64)" data_header="$(echo "$image" | base64 -d | sed -n '2p')" data="$(echo "$image" | base64 -d | tail -n +3 | base64)" +hex_size32() { + printf '%08x' "$1" | sed -e 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/g' +} hex_size() { printf '%04x' "$1" | sed -e 's/\(..\)\(..\)/\\x\2\\x\1/g' } size="$(echo "$data" | base64 -d | wc -c)" -size="$(hex_size "$(("$size" + 10))")" +size="$(hex_size32 "$(("$size" + 10))")" size_x="$(hex_size "$(echo "$data_header" | cut -d' ' -f 1)")" size_y="$(hex_size "$(echo "$data_header" | cut -d' ' -f 2)")" ./init_printer.sh # Upload graphics data -printf '\x1D(L' > $dev +printf '\x1D8L' > $dev printf "$size" > $dev printf '0p0' > $dev printf '\1\1' > $dev # bx, by (1 or 2) @@ -28,7 +31,7 @@ printf "$size_y" > $dev # size y echo "$data" | base64 -d > $dev # Print graphics data -printf '\x1D(L\2\0' > $dev +printf '\x1D8L\2\0\0\0' > $dev printf '02' > $dev ./cut_paper.sh