rounded corners on thumbs
Elgan |
|
---|---|
Okei so today i didnt get much work on actual things done, spent pretty much all the day after work researching and getting to know GD a little more and playing about and breaking up with some girl again. so anyway: GD has alot of funcs , i wanted to get to know it a little more in deph. now im tired, angry, and dont care anymore , work int he morning and thought it would be nicer to just share and chat!
THe lil function below i use after after making a thumbnail to round the corners of it. Posting it here as its still WIP. You can see some outcomes here: ![]() ![]() ![]() ![]() ![]() More here As you may notice on some conflicting colours (ie my hat) it still tries to make it transparent on the blend? Any ideas? Note, i do know jpegs etc dont have an alpha channel, and some of you with poor browsers may get some issues.
function round_thumbnail($path)
{
$extension = get_extension($path);
switch($extension)
{
case 'gif':
$image = imagecreatefromgif($path);
break;
case 'png':
$image = imagecreatefrompng($path);
break;
default:
$image = imagecreatefromjpeg($path);
break;
}
// Get width and height
$x = imagesx($image);
$y = imagesy($image);
// grey
$grey = 0x007F7F7F;
// (black)
$c_bg = 0x00000000;
$new_img = imagecreatetruecolor($x,$y);
imageFilledRectangle($new_img, 0,0, $x,$y, $grey);
$step = 18;
$angle = 40;
// draw the head
imagearc($new_img, $step, $step, $angle, $angle, 180, 270, $transparent);
imagearc($new_img, $x - $step, $step, $angle, $angle, 270, 0, $transparent);
imagearc($new_img, $x - $step,$y - $step, $angle, $angle, 0, 90, $transparent);
imagearc($new_img, $step,$y - $step, $angle, $angle, 90, 180, $transparent);
ImageFillToBorder($new_img,0,0,$transparent,$transparent);
ImageFillToBorder($new_img,$x,$y,$transparent,$transparent);
ImageFillToBorder($new_img,0,$y,$transparent,$transparent);
ImageFillToBorder($new_img,$x,0,$transparent,$transparent);
imagecolortransparent($new_img, $transparent);
// so we only rplace on grey
imagelayereffect($new_img, IMG_EFFECT_OVERLAY);
imagecopy($new_img, $image, 0,0, 0,0, $x,$y);
switch($extension)
{
case 'gif':
imagegif($new_img, $path);
break;
case 'png':
imagepng($new_img, $path);
break;
default:
imagepng($new_img, $path);
break;
}
imagedestroy($image);
imagedestroy($new_img);
return;
}
meh sorry ill comment it tomorrow. if any interest. note i just used it like this: sed_createthumb($file_path, $thumbnail_path , $cfg['th_x'],$cfg['th_y'], $cfg['th_keepratio'], $thumbnail_extension, $filename, $file_size, $th_colortext, $cfg['th_textsize'], $th_colorbg, $cfg['th_border'], $cfg['th_jpeg_quality']);
if(1)
{
round_thumbnail($thumbnail_path);
}
|