Skip to content

Instantly share code, notes, and snippets.

@ademalp
Last active December 17, 2015 09:59
Show Gist options
  • Save ademalp/5591346 to your computer and use it in GitHub Desktop.
Save ademalp/5591346 to your computer and use it in GitHub Desktop.
<?php
$i = isset($_GET['f']) ? $_GET['f'] : "";//$yok;
$x = isset($_GET['w']) ? intval($_GET['w']) : 100;
$y = isset($_GET['h']) ? intval($_GET['h']) : 0;
$noimage = false;
if (is_file($i))
{
list($w, $h, $t) = getimagesize($i);
if (in_array($t, array(1, 2, 3))) {
if($y==0)
{
$y = (int)($x * $h / $w);
}
if (($w / $h) >= ($x / $y)) {
$b = ceil($x * $h / $w);
$a = ceil($w * $b / $h);
} else {
$a = ceil($w * $y / $h);
$b = ceil($a * $h / $w);
}
$bx = ceil(($y - $b) / 2);
$ax = ceil(($x - $a) / 2);
$source = imagecreate($w, $h);
switch ($t) {
case 1:
$source = imagecreatefromgif($i);
break;
case 2:
$source = imagecreatefromjpeg($i);
break;
case 3:
$source = imagecreatefrompng($i);
break;
}
}else{
$noimage = true;
}
}else{
$noimage = true;
}
$thumb = imagecreatetruecolor($x, $y);
imagealphablending($thumb, false);
$alpha = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
imagefill($thumb, 0, 0, $alpha);
imagesavealpha($thumb, true);
if($noimage==false)
{
imagecopyresampled($thumb, $source, $ax, $bx, 0, 0, $a, $b, $w, $h);
}else{
$color = imagecolorallocate($thumb, 200, 200, 200);
for($i=0;$i<5;$i++)
imageellipse($thumb, $x/2, $y/2, $x-$i, $x-$i, $color);
}
header('Content-Type: image/png');
imagepng($thumb);
imagedestroy($thumb);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment