private function optimize($imagePath)
 {
     chmod($imagePath, 0777);
     $image = new Respimg($imagePath);
     $width = getimagesize($imagePath);
     if ($width > 54) {
         $width = 54;
     }
     $image->smartResize($width, 0, true);
     $image->cropImage($width, $width, 0, 0);
     $image->writeImage($imagePath);
     Respimg::optimize($imagePath, 0, 1, 1, 1);
 }
Example #2
0
$path_raster_o = __DIR__ . '/generated/default/raster';
$path_svg_i = __DIR__ . '/assets/svg';
$path_svg_o = __DIR__ . '/generated/default/svg';
// widths
$widths = array(320, 640, 1280);
// resize raster inputs
if ($dir = opendir($path_raster_i)) {
    while (($file = readdir($dir)) !== false) {
        $base = pathinfo($file, PATHINFO_BASENAME);
        $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
        if (in_array($ext, $exts)) {
            foreach ($widths as $w) {
                echo 'Resizing ' . $file . ' to ' . $w . '…';
                $image = new Respimg($path_raster_i . '/' . $file);
                $image->smartResize($w, 0, true);
                $image->writeImage($path_raster_o . '/' . $base . '-w' . $w . '.' . $ext);
                echo "OK\n";
            }
        }
    }
}
// rasterize SVGs
if ($dir = opendir($path_svg_i)) {
    while (($file = readdir($dir)) !== false) {
        $base = pathinfo($file, PATHINFO_BASENAME);
        $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
        if ($ext === 'svg') {
            foreach ($widths as $w) {
                echo 'Rasterizing ' . $file . ' to ' . $w . '…';
                Respimg::rasterize($path_svg_i . '/' . $file, $path_svg_o . '/', $w, 0);
                echo "OK\n";