Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Created May 27, 2012 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanmckenzie/2816223 to your computer and use it in GitHub Desktop.
Save brendanmckenzie/2816223 to your computer and use it in GitHub Desktop.
function tile_image($source, $wide, $tall) {
$im_src = imagecreatefromjpeg($source);
$im_size = getimagesize($source);
$slice_width = $im_size[0] / $wide;
$slice_height = $im_size[1] / $tall;
$im_dest = imagecreatetruecolor($slice_width, $slice_height);
for ($x = 0; $x < $wide; $x++) {
for ($y = 0; $y < $tall; $y++) {
imagecopy($im_dest, $im_src, 0, 0, $x * $slice_width, $y * $slice_height, $slice_width, $slice_height);
$filename = str_replace('_cropped.jpg', '_tile_', $source) . sprintf('%1$04d', $y) . 'x' . sprintf('%1$04d', $x) . '.jpg';
imagejpeg($im_dest, $filename, 100);
}
}
imagedestroy($im_src);
imagedestroy($im_dest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment