Created
July 1, 2011 03:07
-
-
Save destroytoday/1057794 to your computer and use it in GitHub Desktop.
JPixel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set ( "memory_limit", "1000M"); | |
set_time_limit ('1000'); | |
$tmp = $_FILES['file']; | |
$type = strtolower(strstr ($tmp['name'], ".")); | |
if ($type == '.jpg' || $type == '.jpeg') | |
{ | |
$image = imagecreatefromjpeg ($tmp['tmp_name']); | |
} | |
else | |
{ | |
die("Use a jpg. None of this weird " . substr($type, 1) . " shite."); | |
} | |
$width = imagesx ($image); | |
$height = imagesy ($image); | |
if ($width > 500 || $height > 500) | |
{ | |
die("The image is too big. Try keeping it under 500x500, dude."); | |
} | |
$size = 1; | |
$im = imagecreatetruecolor ($width*8,$height*8); | |
$bg = imagecolorallocate($im, 255, 255, 255); | |
for ($y = 0; $y < floor ($height / $size); $y++) { | |
for ($x = 0; $x < floor ($width / $size); $x++) { | |
$color = imagecolorat ($image, $x * $size, $y * $size); | |
$red = ($color >> 16) & 0xFF; | |
$green = ($color >> 8) & 0xFF; | |
$blue = $color & 0xFF; | |
$gray = round (($red + $green + $blue) / 3); | |
$rect_color = imagecolorallocate($im, $red, $green, $blue); | |
imagefilledrectangle ($im, $x*8, $y*8, ($x+1)*8, ($y+1)*8, $rect_color); | |
$im2 = imagecreatefromgif ("icons/" . (floor ($gray/4)) . ".gif"); | |
imagecopy ($im, $im2, $x*8, $y*8, 0, 0, 8, 8); | |
$rect_color = imagecolorallocatealpha($im, $red, $green, $blue,75); | |
imagefilledrectangle ($im, $x*8, $y*8, ($x+1)*8, ($y+1)*8, $rect_color); | |
} | |
} | |
header ("Content-type: image/gif"); | |
imagegif ($im); | |
imagedestroy ($im); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment