How to create thumbnail images with white 3px border using PHP? any body have the scripts please help me :(
A:
create a jpg (or gif/png) which is 6px heigher and 6px widther than the given thumbnail. take the desired border color as background color. then copy your thumbnail in it with startingpos 3px, 3px ;-)
best practice using imagick library
helle
2010-06-11 08:56:54
A:
Haven't actually tried this but I think something like this might work
<?php
/*
* Function to create a border around an image
*/
function drawBorder($image_name, $r = 0, $g = 0, $b = 0, $thickness = 1)
{
$image = ImageCreateFromJPEG($image_name);
$color = ImageColorAllocate($img, $r, $g, $b);
$x1 = 0;
$y1 = 0;
$x2 = ImageSX($image) - 1;
$y2 = ImageSY($image) - 1;
for($i = 0; $i < $thickness; $i++)
{
ImageRectangle($image, $x1++, $y1++, $x2--, $y2--, $color);
}
return $image;
}
?>
Then run something like
<?php
header('Content-type: image/jpeg');
ImageJPEG(drawBorder("images/foo.jpg", 128, 128, 0, 3));
?>
inquam
2010-06-11 09:18:50
Ahhh... And if you actually wanted WHITE borders (missed that) you just pass 255, 255, 255 as the rgb values.WOuld also probably be nice to have a switch statement to actually check the type of image and then using the appropriate ImageCreateFrom* function.
inquam
2010-06-11 09:24:09
Thank you very much sir
learner
2010-06-11 09:35:04
A:
function addBorderpng($add){
$border=5;
$im=imagecreatefrompng($add);
$width=imagesx($im);
$height=imagesy($im);
$img_adj_width=$width+(2*$border);
$img_adj_height=$height+(2*$border);
$newimage=imagecreatetruecolor($img_adj_width,$img_adj_height);
$border_color = imagecolorallocate($newimage, 255, 255, 255);
imagefilledrectangle($newimage,0,0,$img_adj_width,
$img_adj_height,$border_color);
imagecopyresized($newimage,$im,$border,$border,0,0,
$width,$height,$width,$height); imagepng($newimage,$add,9); chmod("$add",0666);
}
learner
2010-06-11 10:06:34