2021-08-24 18:45:25 +00:00
|
|
|
|
edit:add-var pdf2grey~ [@argv]{
|
|
|
|
|
use re
|
|
|
|
|
use str
|
2021-08-27 19:45:39 +00:00
|
|
|
|
var m = [
|
2021-08-24 18:45:25 +00:00
|
|
|
|
&nb=$false
|
|
|
|
|
&split=50
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
fn _help []{
|
|
|
|
|
echo 'Usage: pdf2gray [-hn (<n>)] <input>.pdf <output>.pdf'
|
|
|
|
|
echo ''
|
|
|
|
|
echo 'Options:'
|
|
|
|
|
echo ' -h Affiche cette aide'
|
|
|
|
|
echo ' -n [0-100] Convertit en noir et blanc. Si un nombre est spécifié, indique le pourcentage de coupure (par défaut: 50)'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_pdf [e]{
|
|
|
|
|
re:match '.*\.pdf$' $e
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_int [e]{
|
|
|
|
|
re:match '^\d+$' $e
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_split [e]{
|
|
|
|
|
and (>= $e 0) (<= $e 100)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (> (count $argv) 0) {
|
2021-08-27 19:45:39 +00:00
|
|
|
|
var e @argv = $@argv
|
2021-08-24 18:45:25 +00:00
|
|
|
|
if (or (eq $e '-h') (eq $e '--help')) {
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
} elif (eq $e -n) {
|
|
|
|
|
m[nb] = $true
|
|
|
|
|
if (== (count $e) 0) {
|
|
|
|
|
echo 'Il manque des arguments après -s'
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
} elif (is_int $argv[0]) {
|
|
|
|
|
e @argv = $@argv
|
|
|
|
|
if (is_split $e) {
|
|
|
|
|
m[split] = $e
|
|
|
|
|
} else {
|
|
|
|
|
echo 'L’argument (optionnel) après -s doit être compris entre 0 et 100'
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} elif (not (is_pdf $e)) {
|
|
|
|
|
echo 'Argument non reconnu: '$e
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
} elif (not (has-key $m input)) {
|
|
|
|
|
m[input] = $e
|
|
|
|
|
} else {
|
|
|
|
|
m[output] = $e
|
|
|
|
|
if (> (count $argv) 0) {
|
|
|
|
|
echo 'Trop d’arguments: '$@argv
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (not (has-key $m input)) {
|
|
|
|
|
echo 'Manque le input'
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
} elif (not (has-key $m output)) {
|
|
|
|
|
echo 'Manque le output'
|
|
|
|
|
_help
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 19:45:39 +00:00
|
|
|
|
var params = [-colorspace gray]
|
2021-08-24 18:45:25 +00:00
|
|
|
|
if $m[nb] {
|
|
|
|
|
@params = (all $params) -threshold $m[split]'%'
|
|
|
|
|
}
|
|
|
|
|
@params = $@params $m[input] $m[output]
|
|
|
|
|
echo 'Commande: convert '(str:join ' ' $params)
|
|
|
|
|
convert $@params
|
2021-08-27 19:45:39 +00:00
|
|
|
|
var
|