Skip to content

Instantly share code, notes, and snippets.

@GuilhermeBarile
Created August 29, 2011 18:43
Show Gist options
  • Save GuilhermeBarile/1179083 to your computer and use it in GitHub Desktop.
Save GuilhermeBarile/1179083 to your computer and use it in GitHub Desktop.
Generate formatted CSS from image files with width/height info
#!/bin/bash
# ~/bin/gencss.sh
# specify a prefix or suffix using
# PREFIX="#" SUFFIX=" .image" ~/bin/gencss.sh *.png
FORMAT="$PREFIX%t$SUFFIX { background: url('%i') no-repeat center center; width: %wpx; height: %hpx; }"
until [ -z "$1" ] # Until all parameters used up . . .
do
identify -format "$FORMAT" $1
shift
done
# Examples
$ ls jobs/
2_sargento.png botton_base_vermelho.png coletor_do_trafico.png gerente_da_boca.png piloto_de_fuga.png soldado_do_trafico.png
aviazinho.png braco_direito.png coronel.png intermediario.png recruta.png subtenente.png
botton_base_azul.png cabo.png dono_do_morro.png major.png sargento.png tenente.png
botton_base_padrao.png capitao.png fogueteiro.png matador_de_aluguel.png soldado.png
$ PREFIX="." gencss.sh jobs/*
.2_sargento { background: url('jobs/2_sargento.png') no-repeat center center; width: 42; height: 42; }
.aviazinho { background: url('jobs/aviazinho.png') no-repeat center center; width: 42; height: 42; }
.botton_base_azul { background: url('jobs/botton_base_azul.png') no-repeat center center; width: 48; height: 50; }
.botton_base_padrao { background: url('jobs/botton_base_padrao.png') no-repeat center center; width: 48; height: 50; }
.botton_base_vermelho { background: url('jobs/botton_base_vermelho.png') no-repeat center center; width: 48; height: 50; }
.braco_direito { background: url('jobs/braco_direito.png') no-repeat center center; width: 42; height: 42; }
.cabo { background: url('jobs/cabo.png') no-repeat center center; width: 42; height: 42; }
.capitao { background: url('jobs/capitao.png') no-repeat center center; width: 42; height: 42; }
.coletor_do_trafico { background: url('jobs/coletor_do_trafico.png') no-repeat center center; width: 42; height: 42; }
.coronel { background: url('jobs/coronel.png') no-repeat center center; width: 42; height: 42; }
.dono_do_morro { background: url('jobs/dono_do_morro.png') no-repeat center center; width: 42; height: 42; }
.fogueteiro { background: url('jobs/fogueteiro.png') no-repeat center center; width: 42; height: 42; }
.gerente_da_boca { background: url('jobs/gerente_da_boca.png') no-repeat center center; width: 42; height: 42; }
.intermediario { background: url('jobs/intermediario.png') no-repeat center center; width: 42; height: 42; }
.major { background: url('jobs/major.png') no-repeat center center; width: 42; height: 42; }
.matador_de_aluguel { background: url('jobs/matador_de_aluguel.png') no-repeat center center; width: 42; height: 42; }
.piloto_de_fuga { background: url('jobs/piloto_de_fuga.png') no-repeat center center; width: 42; height: 42; }
.recruta { background: url('jobs/recruta.png') no-repeat center center; width: 42; height: 42; }
.sargento { background: url('jobs/sargento.png') no-repeat center center; width: 42; height: 42; }
.soldado { background: url('jobs/soldado.png') no-repeat center center; width: 42; height: 42; }
.soldado_do_trafico { background: url('jobs/soldado_do_trafico.png') no-repeat center center; width: 42; height: 42; }
.subtenente { background: url('jobs/subtenente.png') no-repeat center center; width: 42; height: 42; }
.tenente { background: url('jobs/tenente.png') no-repeat center center; width: 42; height: 42; }
# Prefix and Suffix
$ PREFIX=".bandido #" SUFFIX=" .image" gencss.sh jobs/bandido/*
.bandido #acerto_devedor .image { background: url('jobs/bandido/acerto_devedor.png') no-repeat center center; width: 160px; height: 100px; }
.bandido #achar_infiltrado .image { background: url('jobs/bandido/achar_infiltrado.png') no-repeat center center; width: 160px; height: 100px; }
.bandido #ajuda .image { background: url('jobs/bandido/ajuda.png') no-repeat center center; width: 160px; height: 100px; }
.bandido #ajuda_tranp .image { background: url('jobs/bandido/ajuda_tranp.png') no-repeat center center; width: 160px; height: 100px; }
.bandido #alemao .image { background: url('jobs/bandido/alemao.png') no-repeat center center; width: 160px; height: 100px; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment