Commit bd63309c98148c52650ffaa583ccc9db4469ae13
Committed by
Daniela Feitosa
1 parent
8840541e
Exists in
master
and in
22 other branches
ActionItem1076: A new script to run in the server will genetrate any needed thum…
…b. See the help of script/generate-image-thumb
Showing
1 changed file
with
49 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +append="$1" | ||
| 4 | +size="$2" | ||
| 5 | + | ||
| 6 | +if test \! -d public/thumbnails -o \! -d public/articles \ | ||
| 7 | + -o -z "$append" -o -z "$size"; then | ||
| 8 | + echo " | ||
| 9 | + Rode esse script na raiz do Noosfero para criar um tipo de thumbnail | ||
| 10 | + para as imagens-artigo. | ||
| 11 | + | ||
| 12 | + Uso: | ||
| 13 | + $( basename "$0" ) <append-name> <size> | ||
| 14 | + | ||
| 15 | + <append-name>: será adicionado ao nome da imagem, antes da extensão. | ||
| 16 | + Exemplo: | ||
| 17 | + $( basename "$0" ) thumb '100x100>' | ||
| 18 | + teste.jpg => teste_thumb.jpg | ||
| 19 | + | ||
| 20 | + <size>: deve ser um argumento gemométrico válido para o ImageMagick | ||
| 21 | + http://imagemagick.org/script/command-line-processing.php#geometry | ||
| 22 | + Exemplo: 200x200> redimensiona proporcionalmente apenas se a imagem | ||
| 23 | + for maior que o espaço. | ||
| 24 | + | ||
| 25 | + Esse script varre o diretório de imagens-artigo | ||
| 26 | + \"noosfero-path/public/articles/...\" e verifica se um arquivo de | ||
| 27 | + mesmo nome e com <append-name> existe no diretório de thumbnails | ||
| 28 | + \"noosfero-path/public/thumbnails/...\". Apenas se ele não existir | ||
| 29 | + o mesmo será criado. Se deseja redimensionar um tipo já existente, | ||
| 30 | + primeiro delete todas as ocorrencias. | ||
| 31 | + " | ||
| 32 | + exit 1 | ||
| 33 | +fi | ||
| 34 | + | ||
| 35 | +cd public/articles | ||
| 36 | +find * | egrep '\.(jpe?g|png|gif|xpm|svg|ico|pnm|tiff?)$' | | ||
| 37 | +while read img; do | ||
| 38 | + thumb="$( echo "../thumbnails/$img" | sed -r "s/(\.[^.]+)$/_$append\1/" )" | ||
| 39 | + if test -e "$thumb"; then | ||
| 40 | + echo " ok $img" | ||
| 41 | + else | ||
| 42 | + mkdir -p "$( dirname "$thumb" )" 2>- | ||
| 43 | + echo " NOVO $img" | ||
| 44 | + if ! convert "$img" -resize "$size" "$thumb"; then | ||
| 45 | + echo -e "Deu Merda...\n" | ||
| 46 | + fi | ||
| 47 | + fi | ||
| 48 | +done | ||
| 49 | + |