Jump to content

help about php imaging


leodirk

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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);  

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.