Skip to content

Instantly share code, notes, and snippets.

@pcostesi
Created March 31, 2011 00: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 pcostesi/895586 to your computer and use it in GitHub Desktop.
Save pcostesi/895586 to your computer and use it in GitHub Desktop.
<?php
if(isset($_POST['img']) && !empty($_POST['img'])) {
$file = uniqid().".jpeg";
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
$image=imagecreatetruecolor($width, $height) or die('no hay GD!');
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
$int = hexdec($data[$i++]);
$color = imagecolorallocate($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
imagesetpixel($image, $x, $y, $color);
}
}
imagejpeg($image, $file, 95);
imagedestroy($image);
} else die("error");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment