Jump to content

Recommended Posts

So its a virtual pet script I'm making.

This script changes the image of the pet with time.

It also puts the user's name,in text on the image.

For some reason It doesnt turn out too well=

http://amiteka.comli.com/viewpet_forum.php?id=1

:shrug: Can someone tell me what is wrong with the script or how I can make it show something like; Error on line #

 

<?php

require_once('./inc/config.php');

function greaterDate($dformat, $beginDate, $endDate)
{
    $subtract = $endDate - $beginDate;
    if($subtract > 0) {
    return 1;
    }
    else {
    return 0;
    }
}

function check(){
$pid = mysql_real_escape_string($_GET['id']);
$result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = 

'{$pid}'");

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

$results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row

[petid]}'");
$pet = mysql_fetch_array($results);

$results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row

[adopter]}'");
$usercc = mysql_fetch_array($results2);

if(greaterDate(".", $row[fulldate], date('Ymd')) > 0) {
$im = showpet_forum($pet[adulturl]);
$image = imagecreatefrompng($im);
return imagepng($image);


header('Content-type: image/png');


} elseif(greaterDate(".", $row[halfdate], date('Ymd')) > 0 && greaterDate

(".", $row[fulldate], date('Ymd')) <= 0){

$im = showpet_forum($pet[teenurl]);
$image = imagecreatefrompng($im);
return imagepng($image);


header('Content-type: image/png');


} elseif(greaterDate(".", $row[halfdate], date('Ymd')) <= 0){

$im = showpet_forum($pet[babyurl]);
$image = imagecreatefrompng($im);
return imagepng($image);




}
}
}

echo check();

?>

 

Thank you for any help.

Link to comment
https://forums.phpfreaks.com/topic/223060-adding-text-to-image-script/
Share on other sites

Well your host was reviewing your site when I looked.

You are seeing this page because the system administrator of 000webhost.com is currently checking this website for malicious content. blah blah.

 

Is quite a curious code you have there.

I'm wondering what the values are in the rows. As if are you really getting values.

Is your error reporting turned on in php.ini

 

Maybe try to break down the selects and try to echo some of the row results to see what they actually are.

 

I don't think these type lines are gonna work, are they actual image locations?

$im = showpet_forum($pet[teenurl]);

 

They should be actual locations to an image, and quoted.

 

And where is $check() coming from?

 

Another thing, the header should come before the display of the image.

$image = imagecreatefrompng($im);

header('Content-type: image/png');

return imagepng($image);

 

also should destroy the temporary image each time or will run out of memory fast

imagedestroy($image);

 

Lets stop there for now, lol.

 

You should try doing basic imagecreatefrom examples first to test the images, then try to place that into your functions the way you want.

http://www.php.net/manual/en/book.image.php

 

Here is a simple add text to a png image code for you.

 

Can pass your values to this script from your function instead of duplicating the gd image code every spot.

Is numerous ways to do this.

 

<?php
//sample usages if name file text-image.php,also full url's preferable
//<img src="./text-image.php?text=Name&imagelocation=./image/picture.png" />
header('Content-type: image/png');
$text = "No Name";
$text = mysql_real_escape_string($_GET['text']);
//$imagelocation = "image/quickdemon.png";
$imagelocation  = mysql_real_escape_string($_GET['imagelocation']);
$im = imagecreatefrompng($imagelocation);
$color = imagecolorallocate($im, 128, 192, 128);//these 3 numbers change the color
$font = 'font.ttf';//use any font and point to the ttf file
$fontsize = 10;//size of font
$size = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
$dx = (imagesx($im)) - (abs($size[2]-$size[0])) - 20; //calculate the location to start the text
imagettftext($im, $fontsize, 0, $dx, 13, $color, $font, $text);//merge it all
imagepng($im);//create it
imagedestroy($im);//destroy it
?>

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.