Utilizando la herramienta pngcrush disponible con apt-get y creando un pequeño shell script podemos optimizar todas las imagenes .png que queramos dentro de un árbol de directorios recursivamente.
El script requiere como parámetro el path a partir del cual se buscarán los ficheros y por seguridad no permite especificar el path raíz de nuestro linux.
Ojo que sobreescribe los ficheros, así que tener cuidado y haceros copia de seguridad por si acaso :)
Aquí os dejo el script para optimizar recursivamente todas vuestras imagenes png.
#!/bin/sh
if [ $# -lt 1 ]
then
echo "Missing path parameter to search into"
exit 2
fi
if [ "$1" = "/" ]
then
echo "root folder is not allowed"
exit 2
fi
read -p "Crush all PNG files under $1 folder? yes / no ?" answer
if [ "$answer" != "yes" ]
then
echo "Cancelled"
exit 2
fi
echo "Looping inside $1"
for png in `find $1 -name "*.png"`
do
echo "crushing $png"
pngcrush "$png" temp.png
mv -f temp.png $png
done;
Nota: la linea pngcrush podeis personalizarla a vuestro gusto, por ejemplo añadiendo -brute para que la compresion sea superior (aunque mucho más lento).
He conseguido aproximadamente un 10% de reducción sin usar brute básicamente porque no me apetece esperar varias horas (eran cientos de ficheros)
Espero que os sirva :)
Artículos de opinión, videos de humor, música, tecnología, cosas extrañas, críticas, trailers de películas y ocio en general
Mostrando entradas con la etiqueta tutorial. Mostrar todas las entradas
Mostrando entradas con la etiqueta tutorial. Mostrar todas las entradas
jueves, 1 de noviembre de 2012
viernes, 9 de octubre de 2009
Unit testing en PHP - PHPUnit
Para descargar las librerías de PHPUnit ejecutamos en consola:
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
Asegurarse de tener PEAR instalado
O actualizardo a la última versión con el comando: pear upgrade pear
Posteriormente, preparamos un test:
require_once 'PHPUnit/Framework/TestCase.php';
class ArrayTest extends PHPUnit_Framework_TestCase {
public function testNewArrayIsEmpty() {
// Create the Array fixture.
$fixture = Array();
// Assert that the size of the Array fixture is 0.
$this->assertEquals(0, sizeof($fixture));
}
public function testArrayContainsAnElement() {
// Create the Array fixture.
$fixture = Array();
// Add an element to the Array fixture.
$fixture[] = 'Element';
// Assert that the size of the Array fixture is 1.
$this->assertEquals(2, sizeof($fixture));
}
}
Y lo ejecutamos:
phpunit --verbose mypath/myscript.php
El resultado de éste test será un error, puesto que creamos un array con un elemento y solicitamos que nos compruebe si dicho array tiene dos elementos.
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
Asegurarse de tener PEAR instalado
O actualizardo a la última versión con el comando: pear upgrade pear
Posteriormente, preparamos un test:
require_once 'PHPUnit/Framework/TestCase.php';
class ArrayTest extends PHPUnit_Framework_TestCase {
public function testNewArrayIsEmpty() {
// Create the Array fixture.
$fixture = Array();
// Assert that the size of the Array fixture is 0.
$this->assertEquals(0, sizeof($fixture));
}
public function testArrayContainsAnElement() {
// Create the Array fixture.
$fixture = Array();
// Add an element to the Array fixture.
$fixture[] = 'Element';
// Assert that the size of the Array fixture is 1.
$this->assertEquals(2, sizeof($fixture));
}
}
Y lo ejecutamos:
phpunit --verbose mypath/myscript.php
El resultado de éste test será un error, puesto que creamos un array con un elemento y solicitamos que nos compruebe si dicho array tiene dos elementos.
Etiquetas:
php,
phpunit,
programación,
tutorial,
unit testing
Suscribirse a:
Entradas (Atom)