Saturday, April 3, 2010

Dynamic Image with PHP

<?php 

function addText($image, $text, $x, $y, $font, $color, $fontsize){
$txt = imagettftext($image, $fontsize, 0, $x, $y, $color, $font, $text);
return $txt;
}

function createImage($width,$height){
$im = ImageCreate($width, $height);
return $im;
}

function backgroundColor($color){
$imf = ImageFill($image, 0, 0, $color);
return $imf;
}

function setImageType($image, $type){

    //Tell the browser what kind of file is come in 
    header("Content-Type: image/$type");

if($type=="jpeg") ImageJpeg($image);
elseif($type=="png") ImagePng($image);
elseif($type=="jpeg") ImageJpeg($image);
elseif($type=="gif") ImageGif($image); 
}
   
function freeImage($image){
    ImageDestroy($image);
}


 


    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);




?>

No comments:

Post a Comment