[SOLVED] writing text to image
Posted: Wed Jun 28, 2006 6:46 pm
Greetings,
I have small question for experts. I have this code snippets that works fine, however I'm trying to make it a small class. Problem I'm having with the class is that it doesn't write any data to the image.
Here's the code snippet.
And here's the class
And this is when how class gets called
$formFields definitley has data. imagettftext() returns array of data for each itteration. So.....
Any input is very much appreciated.
I have small question for experts. I have this code snippets that works fine, however I'm trying to make it a small class. Problem I'm having with the class is that it doesn't write any data to the image.
Here's the code snippet.
Code: Select all
$im = imagecreatefromjpeg($original);
$fontType = 'fonts/tahoma.ttf';
$fontSize = 10;
$fontAngle = 0;
$fontColor = imagecolorallocate($im, 0, 0, 0);
foreach ( $formFields as $f )
{
$top = $f['top_pos'] + 14;
$left = $f['left_pos'];
$type = $f['type'];
$value = $f['value'];
imagettftext($im, $fontSize, $fontAngle, $left, $top, $fontColor, $fontType, $value);
}
// output the image
//header("Content-type: image/png");
imagejpeg('new-name.jpg');Code: Select all
class FormCapture
{
var $_fontType = 'fonts/tahoma.ttf';
var $_fontSize = 10;
var $_fontAngle = 0;
var $_fontAdjustment = 14;
var $_fontColor;
var $_image;
function FormCapture( $image )
{
$this->_image = imagecreatefromjpeg( $image );
}
function setFontColor( $red = 255, $green = 255, $blue = 255 )
{
$this->_fontColor = imagecolorallocate( $this->_image, $red, $green, $blue );
return $this->_fontColor;
}
function writeImageData( $data )
{
foreach( $data as $d )
{
$top = $d['top_pos'] + $this->_fontAdjustment;
$left = $d['left_pos'];
$type = $d['type'];
$value = $d['value'];
imagettftext( $this->_image,
$this->_fontSize,
$this->_fontAngle,
$left,
$top,
$this->_fontColor,
$this->_fontType,
$value );
}
}
function saveImage( $name, $quality = 90 )
{
imagejpeg( $this->_image, $name, $quality );
}
}Code: Select all
$fc = new FormCapture($original);
$fc->writeImageData( $formFields );
$fc->saveImage('new-name2.jpg');Any input is very much appreciated.