leodirk Posted December 31, 2007 Share Posted December 31, 2007 Alright so I am working on my mother's work website and I need to be able to make a image with php that uses the same default background image, text from the database depending on which page they are viewing, and a picture also from the database that is generated dependent on the ID of the page. Sorry if that doesn't make any since it is kind of hard for me to describe. It would be awesome if someone could contact me about it on AIM or MSN if they wanted seeing how i have questions/problems with coding it a lot. It is my first self built website anyway. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/ Share on other sites More sharing options...
leodirk Posted January 1, 2008 Author Share Posted January 1, 2008 Still can't figure this out =s. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-427221 Share on other sites More sharing options...
tippy_102 Posted January 1, 2008 Share Posted January 1, 2008 What you want to do is pretty much the same as adding a watermark to an image. There is a tutorial here: http://www.sitepoint.com/article/watermark-images-php or search the word "watermark" on this forum and you will get lots of examples. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-427394 Share on other sites More sharing options...
leodirk Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks I got the two images to work fine but I can't seem to get the text working how I want it to. If I use imagestring() the font wont get bigger than font size 5 which is too small for what I am doing. And when I try to use imagettftext() the image just wont load. I've tried a ton of various things I found off the internet but none of it is working for me. Oh and just in case it may help, the images are merged with imagecopy() because imagecopymerge() wont support png-24. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-428542 Share on other sites More sharing options...
tippy_102 Posted January 2, 2008 Share Posted January 2, 2008 Why don't you post your code so we can have a look. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-428610 Share on other sites More sharing options...
leodirk Posted January 2, 2008 Author Share Posted January 2, 2008 lol sorry, here it is. The output is a sheet for a class the store has, with the image of the project/the watermark somewhere (its current location isnt where it should be, ill fix that later). And I need to display the name of the class at the top, and some other information down the rest of the sheet. <?php $host="localhost"; $username="username"; $password="password"; $db_name="db"; $tbl_name="tbl"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $id=$_GET['id']; $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); header('content-type: image/jpeg'); $image_path= "images/thumbs/"; $url= $image_path . $rows['pic']; $watermark = imagecreatefrompng('watermark.png'); $watermarks = imagecreatefromjpeg($url); $watermark_width = imagesx($watermarks); $watermark_height = imagesy($watermarks); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg('classes.jpg'); $size = getimagesize($url); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopy($image, $watermarks, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); //below was just basically me testing out random imagettftext and imagestring commands. $name = $rows['name']; $font = "verdana.ttf"; $angle = '0'; $red = imagecolorallocate($image, 255, 0, 0); //imagettftext($image, 16, $angle, $x, 35, $colour1, $font, $name); //imagettftext($image, 20, 0, 10, 20, $black, $font, $name); //imagestring($image, 5, 200, 0, $name, $black); imagejpeg($image); imagedestroy($image); imagedestroy($watermarks); imagedestroy($watermark); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-428641 Share on other sites More sharing options...
leodirk Posted January 3, 2008 Author Share Posted January 3, 2008 Any help? =s still can't find out what will print text on that image bigger than font 5.. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-429048 Share on other sites More sharing options...
tippy_102 Posted January 3, 2008 Share Posted January 3, 2008 Adding back in this line: imagettftext($image, 16, $angle, $x, 35, $colour1, $font, $name); works for me. The "16" is the font size - you can increase that to whatever you want. Make sure you have the font in the same directory as your script. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-429066 Share on other sites More sharing options...
leodirk Posted January 3, 2008 Author Share Posted January 3, 2008 when i put it back in, with the font in the folder with it all it says is the url back, "http://192.168.1.130/tbc/viewimage.php?id=7" Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-429114 Share on other sites More sharing options...
leodirk Posted January 5, 2008 Author Share Posted January 5, 2008 Ah.. Still can't get it to work x.x Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-430907 Share on other sites More sharing options...
tippy_102 Posted January 5, 2008 Share Posted January 5, 2008 Here's what I used, and it worked. It is your code - all I did is change the filenames to things I had around. <?php header('content-type: image/jpeg'); $image_path= "images/thumbs/"; $url= 'image.jpg'; $watermark = imagecreatefrompng('watermark.png'); $watermarks = imagecreatefromjpeg($url); $watermark_width = imagesx($watermarks); $watermark_height = imagesy($watermarks); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg('test.jpg'); $size = getimagesize($url); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopy($image, $watermarks, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); $name = 'Name'; $font = "Arial.ttf"; $angle = '0'; $red = imagecolorallocate($image, 255, 0, 0); imagettftext($image, 60, $angle, $x, 25, $colour1, $font, $name); imagejpeg($image); imagedestroy($image); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-430920 Share on other sites More sharing options...
leodirk Posted January 5, 2008 Author Share Posted January 5, 2008 Weird cause it really isn't working for me lol x.x. I even copied your code exactly and renamed images for it and it did the same thing for me. Could it be some settings or something? I have no idea.. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-430945 Share on other sites More sharing options...
tippy_102 Posted January 5, 2008 Share Posted January 5, 2008 It's displaying the url instead of the image? Are you adding any other text to the script? Is anything output before the image? Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-430951 Share on other sites More sharing options...
leodirk Posted January 5, 2008 Author Share Posted January 5, 2008 Yea it just displays the url to the php image when the "imagettftext($image, 15, $angle, 200, 25, $red, $font, $name);" line is in it. And nope the whole php file is just <?php $host="localhost"; $username=""; $password=""; $db_name=""; $tbl_name=""; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $id=$_GET['id']; $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); header('content-type: image/jpeg'); $image_path= "images/thumbs/"; $url= $image_path . $rows['pic']; $watermark = imagecreatefrompng('watermark.png'); $watermarks = imagecreatefromjpeg($url); $watermark_width = imagesx($watermarks); $watermark_height = imagesy($watermarks); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg('classes.jpg'); $size = getimagesize($url); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopy($image, $watermarks, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); $name = $rows['name']; $font = "Verdana.ttf"; $angle = '0'; $red = imagecolorallocate($image, 255, 0, 0); imagettftext($image, 15, $angle, 200, 25, $red, $font, $name); imagejpeg($image); imagedestroy($image); imagedestroy($watermarks); imagedestroy($watermark); ?> and thats all thats in it. Quote Link to comment https://forums.phpfreaks.com/topic/83892-help-about-php-imaging/#findComment-430955 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.