$arg, 'width' => $infos[0], 'height'=> $infos[1], ); if ($infos[0] > $width) $width = $infos[0]; $height += $infos[1]; } if (empty($images)) { die("No images to sprite\n"); } ksort($images); $pos = 0; $css = ''; $im = new Imagick; $im->newImage($width, $height, 'none'); $im->setImageFormat('png'); foreach ($images as $name=>&$image) { $im->compositeImage(new Imagick($image['file']), Imagick::COMPOSITE_OVER, 0, $pos); $css .= '.' . $name . ' { background-position: 0px '.($pos ? '-' . $pos : $pos).'px; '; $css .= 'width: '.$image['width'].'px; height: '.$image['height'].'px; }'; $css .= "\n"; $pos += $image['height']; } $im->writeImage($dest); unset($im); echo $css; ?>