function filter_twirl($source_img_name) {
list($dimx, $dimy, $type, $attr) = getimagesize($source_img_name);
$im_source = imagecreatefromjpeg($source_img_name);
$wp = $dimx * 0.5;
$hp = $dimy * 0.5;
$im_filter = imagecreatetruecolor($dimx, $dimy);
@imagealphablending($im_filter, false);
@imagesavealpha($im_filter, true);
$color_filter = imagecolorallocatealpha($im_filter, 255, 255, 255, 127);
imagefill($im_filter, 0, 0, $color_filter);
$a = atan2(-1.0, $wp - 1.0);
if ($a < 0.0) $a += 2.0 * M_PI;
$dx = $dimx / $a;
$d = sqrt($hp * $hp + $wp * $wp);
$dy = $dimy / $d;
for ($h = 0; $h < $dimy + 1; $h++) {
for ($w = 0; $w < $dimx + 1; $w++) {
$x = ($w - $wp);
$y = ($h - $hp);
$dist = sqrt($x * $x + $y * $y);
$angle = atan2($y, $x);
if ($angle < 0) $angle += 2.0 * M_PI;
$rgb = imagecolorat($im_source, (int)($dimx - $dx * $angle), (int)($dy * $dist));
$a = ($rgb >> 24) & 0xFF;
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$color_filter = imagecolorallocatealpha($im_filter, $r, $g, $b, $a);
imagesetpixel($im_filter, $w, $h, $color_filter);
}
}
header('Content-type: image/jpeg');
imagejpeg($im_filter);
imagedestroy($im_filter);
}
function filter_swirl($source_img_name) {
list($dimx, $dimy, $type, $attr) = getimagesize($source_img_name);
$im_source = imagecreatefromjpeg($source_img_name);
$wp = $dimx * 0.5;
$hp = $dimy * 0.5;
$im_filter = imagecreatetruecolor($dimx, $dimy);
@imagealphablending($im_filter, false);
@imagesavealpha($im_filter, true);
$color_filter = imagecolorallocatealpha($im_filter, 255, 255, 255, 127);
imagefill($im_filter, 0, 0, $color_filter);
$dz = -0.01;
for ($h = 0; $h < $dimy + 1; $h++) {
for ($w = 0; $w < $dimx + 1; $w++) {
$x = ($w - $wp);
$y = ($h - $hp);
$dist = sqrt($x * $x + $y * $y);
$angle = atan2($y, $x);
if ($angle < 0) $angle += 2.0 * M_PI;
$rgb = imagecolorat($im_source, (int)($wp + $dist * cos($angle + $dist * $dz)), (int)($hp + $dist * sin($angle + $dist * $dz)));
$a = ($rgb >> 24) & 0xFF;
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$color_filter = imagecolorallocatealpha($im_filter, $r, $g, $b, $a);
imagesetpixel($im_filter, $w, $h, $color_filter);
}
}
header('Content-type: image/jpeg');
imagejpeg($im_filter);
imagedestroy($im_filter);
}