how to put some text on image on particular area in php using GD -


i want generate online certificates using gd in php, certificate image format ready me. want put candidate name , other details on image text in particular area. have image file in jpg, gif , png format

how create watermark on existing image..

//-------------------------------------------------------------------------  $wwidth  = 280; // set watermark image width $wheight = 50;  // set watermark image height  // create watermark image $watermark = imagecreate( $wwidth, $wheight );      $black = imagecolorallocate( $watermark, 0, 0, 0 );        // define colour use $white = imagecolorallocate( $watermark, 255, 255, 255 );  // define colour use  // create rectangle , fill white imagefilledrectangle( $watermark, 0, 0, $wwidth, $wheight, $white );   // make white transparent #imagecolortransparent ( $watermark, $white );    $font = 'fonts/arial.ttf';  // store path font file  $wtext = "(c) chris maggs ".date('y');   // set watermark text $wsize = "20";                              // set watermark font size   // calculate size of $wtext (requires php/gd ttf support) $box = imagettfbbox( $wsize, 0, $font, $wtext );   $x = ( $wwidth -  ($box[2] - $box[0]) ) / 2;   $y = ( $wheight - ($box[1] - $box[7]) ) / 2;   $y -= $box[7];    // add $wtext image imagettftext( $watermark, $wsize, 0, $x, $y, $black, $font, $wtext );    // save text image temp.png imagepng( $watermark, "uploads/temp.png" );    // cleanup image memory usage imagedestroy( $watermark );    //-------------------------------------------------------------------------  // set path image watermark $input_image = "resources/tenby.jpg";   // read in text watermark image $watermarkimage = imagecreatefrompng( "uploads/temp.png" );    $watermark_width  = imagesx( $watermarkimage ); // width of image resource  $watermark_height = imagesy( $watermarkimage ); // height of image resource     // create new image resource $image = imagecreatefromjpeg( $input_image );  // find size of original image , read array       $size = getimagesize( $input_image );   // set positions of watermark on image $dest_x = $size[0] - $watermark_width;     $dest_y = $size[1] - $watermark_height;      // merge 2 image resources.. imagecopymerge($image, $watermarkimage, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 50);     // option 1 : save watermarked image watermarked.jpg  imagejpeg( $image, "uploads/watermarked.jpg" );  // option 2 : output watermarked image header("content-type: image/jpeg"); imagejpeg( $image );  // delete text watermark image unlink( "uploads/temp.png");   // cleanup image memory usage imagedestroy( $image );     

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -