Fenec
Fenec

Reputation: 1222

How to make circled thumbnails using GD

I would like to make a circled thumbnails using GD library. Is there're any ready solutions for this? I've seen libraries only for rounded corners yet.

Upvotes: 0

Views: 206

Answers (1)

Den
Den

Reputation: 601

Here is the script i use. It just overlays my thumbnail with a half-transparent pattern, which makes the thumbnail with some shape effect.

ini_set("memory_limit","64M");
ini_set("gd.jpeg_ignore_warning", 1);
$img_name=$_GET[f];
$type=$_GET[type];
if (isset($img_name)) {
 $img_name = $_SERVER["DOCUMENT_ROOT"]."/catalog/".$img_name;
 $info = @getimagesize($img_name);
 $ext = @$info[2];
 $header = @$info['mime'];
 $board = ImageCreateFrompng("images/item".$type.".png");
 $im   = ImageCreateTrueColor(170,140);
 $bg = imagecolorallocate($im, 255, 255, 255);
 imagefill($im,0,0,$bg);
 header("Content-type: $header"); 
switch($ext) {
  case 1: { // GIF
    $img = @imagecreatefromgif($img_name);
    if ($img) {
      imagecopyresized($im, $img, (170-$info[0]), 0, 0, 0, @$info[0], @$info[1],     @$info[0], @$info[1]);
  imagecopy($im, $board, 0, 0, 0, 0, 170, 140);
  imagegif($im, '', 100);
  return $chache_fn;
} break;
  }
  case 2: { // JPG
    $img = @imagecreatefromjpeg($img_name);
    if ($img) {
      imagecopyresized($im, $img, (170-$info[0]), 0, 0, 0, @$info[0], @$info[1],     @$info[0], @$info[1]);
      imagecopy($im, $board, 0, 0, 0, 0, 170, 140);
      imagejpeg($im, '', 100);
    } break;
  }
  case 3: { // PNG
    $img = @imagecreatefrompng($img_name);
    if ($img) {
      imagecopyresized($im, $img, (170-$info[0]), 0, 0, 0, @$info[0], @$info[1],     @$info[0], @$info[1]);
      imagecopy($im, $board, 0, 0, 0, 0, 170, 140);
      imagepng($im, '', 9);
    } break;
  }
  case 6: { // BMP
    $img = @imagecreatefromwbmp($img_name);
    if ($img) {
      imagecopyresized($im, $img, (170-$info[0]), 0, 0, 0, @$info[0], @$info[1],     @$info[0], @$info[1]);
      imagecopy($im, $board, 0, 0, 0, 0, 170, 140);
      imagewbmp($im, '', 100);
    } break;
  }
}
}

Upvotes: 1

Related Questions