SitePoint Sponsor |
|
User Tag List
Results 1 to 1 of 1
Thread: Adding a "Stroke" using GD2
Hybrid View
-
Jun 1, 2003, 07:23 #1
- Join Date
- Nov 2001
- Location
- UK
- Posts
- 553
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Adding a "Stroke" using GD2
I'm currently working on a pretty simple script which takes an image, and creates a thumbnail using GD2.
Despite my inexperience with GD, I've managed to get this far with the help of a tutorial.
However in addition to creating a thumbnail, I'd like to add a 1px black stroke (border) around the image.
This is the function I'm currently using to generate the image.
PHP Code:// begin createthumb
function createthumb($name,$filename,$new_w,$new_h){
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/png/",$system[1])){
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$thumb_w=$new_w;
$thumb_h=$new_h;
// below only works with gd2
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
// end gd2-only code
if (preg_match("/png/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
Many thanksRegards, Ant.
Bookmarks