Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndreiTelteu/e7b6cb7b5abc16f1c0185219dd411915 to your computer and use it in GitHub Desktop.
Save AndreiTelteu/e7b6cb7b5abc16f1c0185219dd411915 to your computer and use it in GitHub Desktop.
With this script you can split a super long image in how many parts you want, and stack them. Like a long ecg chart: https://i.imgur.com/ZlwMNRz.png
<?php
$source_path = 'super-long-image.png';
$destination_path = 'new-image.png';
$parts = 3; // in how many parts you want to split the image
$source = imagecreatefrompng($source_path);
$width = imagesx($source);
$height = imagesy($source);
$newWidth = $width / $parts;
$newHeight = $height * $parts;
$splitWidth = $width / $parts;
$splitHeight = $height;
$image = imagecreatetruecolor($newWidth, $newHeight);
for ($i = 0; $i < $parts; $i++) {
imagecopy(
$image, // destination img
$source, // source img
0, // destination X
$i * $splitHeight, // destination Y
$i * $splitWidth, // source X
0, // source Y
$splitWidth, // split source width
$splitHeight // split source height
);
}
imagepng($image, $destination_path);
imagedestroy($image);
imagedestroy($source);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment