Skip to content

Instantly share code, notes, and snippets.

@innermond
innermond / gist:c7e41a1cb869128b37eecadc808bd8be
Created September 8, 2023 18:17
bash:resize and upload to s3
#!/bin/bash
cd "$(dirname "$0")"
shopt -s nocaseglob
rm -frv ./optimized_images/*
mkdir -p ./optimized_images/400w
AWS_PATH="<s3-uri>"
for f in ./unoptimized_images/*.{jpg,jpeg,png}
package main
import (
"fmt"
"strings"
)
type stringsBuilder struct {
strings.Builder
kv map[string]string
@innermond
innermond / gist:de0c11e09d67ccc0bc2b21505130b4ee
Created March 11, 2022 08:14
elastic 8.1 search map corespondence between language codes and long names (from https://www.elastic.co/guide/en/machine-learning/8.1/ml-nlp-classify-text.html)
$lang = [
'af' => 'afrikaans',
'hr' => 'croatian',
'pa' => 'punjabi',
'am' => 'amharic',
'ht' => 'haitian',
'pl' => 'polish',
'ar' => 'arabic',
'hu' => 'hungarian',
'ps' => 'pashto',
#~/bin/bash
shopt -s extglob
# usage ./.partition <$1 path to directory taht contains image files to be converted to pdf> <$2 number of images converted in a lap> <$3 scale "x y" optional> >
# ./.partition path/to/directory 10 "0.9 0.9"
# dependencies: pdftk and cpdf
cd "$1"
@innermond
innermond / gist:bbc634bd25f32295b56f20f18fe7671e
Created November 2, 2021 08:29
scale a svg - width, height, x, y
function scale($svg, $k) {
$rxvbox = '/viewBox="(\d+) (\d+) (\d+) (\d+)"/si';
$rxw = '/width="(\d+)"/si';
$rxh = '/height="(\d+)"/si';
$rxx = '/x="(\d+)"/si';
$rxy = '/y="(\d+)"/si';
$svg = preg_replace_callback($rxvbox, function($m) use ($k) {return 'viewBox="'.$m[1]*$k.' '.$m[2]*$k.' '.$m[3]*$k.' '.$m[4]*$k.'"';}, $svg);
$svg = preg_replace_callback($rxw, function($m) use ($k) {return 'width="'.$m[1]*$k.'"';}, $svg);
$svg = preg_replace_callback($rxh, function($m) use ($k) {return 'height="'.$m[1]*$k.'"';}, $svg);
$svg = preg_replace_callback($rxx, function($m) use ($k) {return 'x="'.$m[1]*$k.'"';}, $svg);
convert <input.image> -sampling-factor 4:2:0 -strip -quality 80 -interlace JPEG -colorspace sRGB -sigmoidal-contrast 5,50% <output.image>
convert <non.webp> -define webp:lossless=false <output.webp>
@innermond
innermond / gist:33f993646d4c1d101c13ff53fd92ae16
Created September 3, 2021 08:47
all images using find with regex
find ./ -type f -regextype posix-extended -regex "\.\/(frontend|uploads)\/.+\.(jpe?g|png)"
@innermond
innermond / gist:4ee8c5329993e02b1718142380ec76e8
Created March 29, 2021 10:45
calculate with aproximation CMYK coverage color for anything can be src of a html img tag
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
@innermond
innermond / gist:73412a5824127b6adfc99d450b324deb
Created February 1, 2021 17:22
calculate median ink coverage of all pages from a pdf FILE
#!/bin/bash
if [ -z $1 ]; then echo "introdu cale fisier"; exit 1; fi
covfile=${1%.*}.cov
# run this block in background
{
gs -o - -sDEVICE=inkcov "$1" > "$covfile"
sed -i -E '/^\S/d' "$covfile"
awk '{c+=$1; m+=$2; y+=$3; k+=$4; next} END{c=c/NR; m=m/NR; y=y/NR; k=k/NR; print "C="c " M="m " Y="y " K="k " T="c+m+y+k}' "$covfile"
@innermond
innermond / gist:17e5e6ab3f0c09d909c98b9bdaca33e9
Created October 6, 2020 10:46
thumbify images or image-like series
for img in <path/to/images>/*<.extension>; do noext="${img%.*}"; other=<path/to/thumb>/"${noext#*/}".<other-extension>; convert -resize 300x "$img" "$other" ; done