Page 1 of 1

how to merge images and text?

Posted: Sun Sep 21, 2008 8:43 pm
by mhonnphp
Hello,

Guys I need to merge 2 images; one from file and the other one from db.
then after merging, I need to input text inside the merged image.
any help or tutorial for this problem??

Thanks and God bless

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 8:47 pm
by josh
gd image library would prolly do the job

http://www.php.net/gd

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 8:56 pm
by mhonnphp
thanks jshpro2 for the quick reply.
anyway here is my code used for this problem.

Code: Select all

 
        header('Content-type: image/jpeg');
    $dbpic = "pictureFromDB.php";
    $watermark = imagecreatefromjpeg($dbpic);  
    
    $watermark_width = imagesx($watermark);  
    $watermark_height = imagesy($watermark);  
    $image = imagecreatetruecolor($watermark_width, $watermark_height);  
    $image = imagecreatefromjpeg('ToMergetemplate.jpg');  
    $size = getimagesize('ToMergetemplate.jpg');  
    $dest_x = 70;
    $dest_y = 350;
    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0,0, $watermark_width, $watermark_height, 100);  
    imagejpeg($image);  
    imagedestroy($image);  
    imagedestroy($watermark); 
       
I'm having problem with imagecreatefromjpeg($dbpic);
but if you change imagecreatefromjpeg($dbpic) with imagecreatefromjpeg(picture.jpg);
its working fine. how can I used db image with imagecreatefromjpeg()
any idea?

Thanks

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 9:00 pm
by josh
I'm having problem with imagecreatefromjpeg($dbpic);

Code: Select all

echo( 'value is correct: ' . (bool)($dbpic=='picture.jpg'));
var_dump( $dbpic );
 

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 9:10 pm
by mhonnphp
ah.. I get your point.
$dbpic = "pictureFromDB.php";
how can i tell imagecreatefromjpeg() that $dbpic output a jpeg file?

pictureFromDB.php code

Code: Select all

 
 
    include('config/connect.inc.php');
    $conn = mysql_connect($host,$user,$pass); 
    $dbCon = mysql_select_db($db);
    $query = "SELECT tcpd_photo FROM tbl_client_per_details where tcpd_id=51";
    $exec = mysql_query($query);
    $rs = mysql_fetch_array($exec, MYSQL_NUM);
 
    // get the image from the db
    $sql = "SELECT image FROM tbl_client_image WHERE image_id=54";
    
    // the result of the query
    $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
    
    // set the header for the image
    header("Content-type: image/jpeg");
    echo mysql_result($result, 0);
    
    // close the db link
    mysql_close($link);
 
 

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 9:13 pm
by josh
the variable is being populated by the database, so I would change the data in the database, perhaps you're selecting the wrong row or something?

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 9:26 pm
by mhonnphp
jshpro2 wrote:the variable is being populated by the database, so I would change the data in the database, perhaps you're selecting the wrong row or something?
pictureFromDB.php is correct. this php file output a jpeg file.
but when I use it in imagecreatefromjpeg()
by :
imagecreatefromjpeg("pictureFromDB.php"); or
$dbpic = "pictureFromDB.php";
imagecreatefromjpeg($dbpic);

I'm having a problem. How can I tell imagecreatefromjpeg($dbpic) or pictureFromDB.php is a jpeg file

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 9:35 pm
by mhonnphp
got it!
I used imagecreatefromjpeg("http://localhost/OFCARD/pictureFromDB.php");
I used URL this tell imagecreatefromjpeg that pictureFromDB..php is a jpeg file.

Thanks jshpro2 because of you I'm able to notice my error.

God bless

Re: how to merge images and text?

Posted: Sun Sep 21, 2008 10:34 pm
by josh
Do you realize youre making a 2nd web request in the background by using URL wrappers ( "http:// in a filename" )?

A better way would be to take the code in that file and push it back to a function