Archive for July, 2009

Creating Image Border


<?php

/*

* This function is for creating image border . Here image1 is the full path of the

* image and border is the border size.

*

* This function returns the image which one is input with a definite image border

* defined by $border varible

*/

/*

* @author : ruzdi + (internet browsing help)

* @parameters : $image is full path of the image , $border is the border size

* @return : null

* @output : image1 will be replaced by the new image

*/

//THIS FUNCTION REPLACE OLD IMAGE BY THE NEW IMSGE AS THE NAME OF $image1 ON THE SAME FOLDER

function imageBorder($image1='image1.jpg',$border=10) {

$im = ImageCreateFromJpeg($image1);

$width = ImageSx($im);

$height = ImageSy($im);

$newimage_width = $width + ( 2*$border ); // this is the new width after adding border

$newimage_height = $height + ( 2*$border ); // this is the new height after adding border

$newimage = imagecreatetruecolor( $newimage_width, $newimage_height );

$border_color = imagecolorallocate( $newimage, 255, 255, 255 ); //here first paremeter is image name and next three are rgb value

imagefilledrectangle($newimage,0,0,$newimage_width,$newimage_height,$border_color);

imageCopyResized($newimage,$im,$border,$border,0,0,$width,$height,$width,$height);

ImageJpeg($newimage,$image1,100);

chmod($image1,0666);

}

/*

* This function is for creating image border . Here image1 is the full path of the

* image and border is the border size.

*

* This function returns the image which one is input with a definite image border

* defined by $border varible

*/

/*

* @author : ruzdi + (internet browsing help)

* @parameters : $image1 is full path of the image , $image2 new imagename, $border is the border size

* @return : null

* @output : A new $image2 will be created on the same folder

*/

//THIS FUNCTION PRODUCE NEW IMAGE AS THE NAME OF $image2 ON THE SAME FOLDER

function imageBorder2($image1='image1.jpg',$image2='image2.jpg',$border=0) {

$im = ImageCreateFromJpeg($image1);

$width = ImageSx($im);

$height = ImageSy($im);

$newimage_width = $width + ( 2*$border ); // this is the new width after adding border

$newimage_height = $height + ( 2*$border ); // this is the new height after adding border

$newimage = imagecreatetruecolor( $newimage_width, $newimage_height );

$border_color = imagecolorallocate( $newimage, 255, 255, 255 ); //here first paremeter is image name and next three are rgb value

imagefilledrectangle($newimage,0,0,$newimage_width,$newimage_height,$border_color);

imageCopyResized($newimage,$im,$border,$border,0,0,$width,$height,$width,$height);

ImageJpeg($newimage,$image2,100);

chmod($image2,0666);

}

imageBorder('replace.jpg',10);

imageBorder2('old.jpg','new.jpg',20);

?>;

click to download

Advertisements