Exemple #1
0
function scale_size($size, $scale_width, $scale_height)
{
    if (preg_match("#(-?[0-9]+)(|px) (-?[0-9]+)(|px)#im", $size, $match)) {
        return print_dimensions($match[1] * $scale_width, $match[3] * $scale_height);
    } else {
        throw new SpritifyException("Invalid size to scale '{$size}'");
    }
}
Exemple #2
0
 }
 if ($background_size) {
     // now work out what this 'background' property will be replaced with
     $desired_width = -1;
     $desired_height = -1;
     if (preg_match("#([0-9]+)px ([0-9]+)px#im", $background_size, $match)) {
         $desired_width = $match[1];
         $desired_height = $match[2];
     } else {
         throw new SpritifyException("Rule '{$head}': Only background-size supported syntax is Xpx Ypx: '{$background_size}'");
     }
     // work out scale
     $total_size = count($sprites) * ($max_sprite_height + $sprite_padding);
     $scale_width = $desired_width / $sizes[0];
     $scale_height = $desired_height / $sizes[1];
     $sprite_size = print_dimensions($max_sprite_width, $total_size);
     // debug
     if ($debug) {
         $css[$rule_index]['properties'][] = array('key' => 'x-desired-size', 'value' => $background_size);
         $css[$rule_index]['properties'][] = array('key' => 'x-total-count', 'value' => count($sprites));
         $css[$rule_index]['properties'][] = array('key' => 'x-actual-size', 'value' => $sizes[0] . " " . $sizes[1]);
         $css[$rule_index]['properties'][] = array('key' => 'x-total-size', 'value' => count($sprites) * ($max_sprite_height + $sprite_padding));
         $css[$rule_index]['properties'][] = array('key' => 'x-scale', 'value' => "{$scale_width} {$scale_height}");
         $css[$rule_index]['properties'][] = array('key' => 'x-sprite-size', 'value' => $sprite_size);
     }
     // scale both background-size and background-scale appropriately
     foreach ($css[$rule_index]['properties'] as $i => $property2) {
         if ($property2['key'] == 'background-size') {
             $css[$rule_index]['properties'][$i]['value'] = scale_size($sprite_size, $scale_width, $scale_height);
         }
         if ($property2['key'] == 'background-position') {