News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Can't get avatar shows up as image?

Started by RealCop1993, April 23, 2014, 10:08:34 AM

Previous topic - Next topic

RealCop1993

Hello,

I'm trying to make singature system for my SMF forum.
So I made everything a'ight just one thing I can't work out... The problem is showing avatar as image in singature image so basicly it's showing image over image.

This is part of my code:


if($style == 1 ) { // STYLE I

$query = "SELECT * FROM `balkanna_members` WHERE `id_member` = '$user_id' LIMIT 1"; // GET THE INFORMATIONS FROM? AND DEFINES ID LIMIT

$result = mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result) == "0") die("ERROR: This ID don't exist."); // INFO

$row = mysql_fetch_assoc($result);

$name = $row['real_name']; // NAME
$group = $row['id_group']; // GROUP


if($sex == 1) $sextext = "Male"; // SEX 1
if($sex == 0) $sextext = "Female"; // SEX 2

// GET THE INFOS FROM PROFILE LINK

global $context, $settings, $modSettings, $db_prefix, $boardurl;

loadMemberData(array($user_id), false, 'profile');
loadMemberContext($user_id);

        $context['status'] = $memberContext[$user_id]['online']['text']; // ONLINE/OFFLINE STATUS
  $context['avatar'] = $memberContext[$user_id]['avatar']['href']; // AVATAR

 
header("Content-type: image/jpeg,image/gif,image/png"); // CHANGES WEB PAGE INTO IMAGE

$Singature = @imagecreatefrompng('potpis.png'); // LOCATION OF PICTURE

$COLOR_BLACK = imagecolorallocate($Singature, 0, 0, 0); // COLORS

$FONT_FIRST = "./Fonts/MPonderosa.ttf"; // FONTS

$ADMINISTRATOR = 'Administrator'; // RANKS

if($group == 1) // GROUPS
{
imagettftext($Singature, 20, 0, 425, 38, $COLOR_BLACK, $FONT_FIRST, $name); // NAME
imagettftext($Singature, 20, 0, 425, 85, $COLOR_BLACK, $FONT_FIRST, $ADMINISTRATOR); // ADMINISTRATOR
}
else
{
// blahblahblah
}

imagettftext($Singature, 20, 0, 100, 100, $BOJA_SIVA, $FONT_SESTI, $context['avatar']); // AVATAR

   
imagepng($Singature);
imagedestroy($Singature);

}


I hope this is right section since it's php to smf. :)

"Wanting to believe the best about people doesn't make it true."

– Dr. House

Dragooon

imagettftext($Singature200100100$BOJA_SIVA$FONT_SESTI$context['avatar']);
Wait, wouldn't this impose avatar's URL?

You should do something like this (I think, I haven't used GD in 3 years)

$avatar imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature$avatar0000imagesx($avatar), imagesy($avatar));

RealCop1993

Quote from: Dragooon on April 23, 2014, 10:19:00 AM
imagettftext($Singature200100100$BOJA_SIVA$FONT_SESTI$context['avatar']);
Wait, wouldn't this impose avatar's URL?

Exactly!



I have try that way and it's not working
Quote from: Dragooon on April 23, 2014, 10:19:00 AM
You should do something like this (I think, I haven't used GD in 3 years)

$avatar = imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature, $avatar, 0, 0, 0, 0, imagesx($avatar), imagesy($avatar));

I did this aswell
$avatarimage = "<img src=\"$context['avatar']\" />";
imagettftext($Signature, 20, 0, 100, 100, $COLOR_BLACK, $FONT_FIRST, $avatarimage); // AVATAR
But no success

"Wanting to believe the best about people doesn't make it true."

– Dr. House

Dragooon

You need to use imagecreatefromstring/imagecreatefrompng and imagecopy. Check out their function reference

RealCop1993

Quote from: Dragooon on April 23, 2014, 10:51:33 AM
You need to use imagecreatefromstring/imagecreatefrompng and imagecopy. Check out their function reference

Yep, checked them but since im newbie with this i'm stucked at creating avatar
I did checked all that already before i asked for help but since i asked every friend of mine to help me solve this problem and they ignored me since here one rule exist ''You must be atleast a bit better than your neighbour/friend'' so i came here to ask for help.
I will freak out it's like i'm working on gold project not some stupid singature system  :-\
Please if you can check once more the whole code and give me some solution more i would appreciate that

"Wanting to believe the best about people doesn't make it true."

– Dr. House

Dragooon

I did :P, does this work?
[php]$avatar imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature$avatar0000imagesx($avatar), imagesy($avatar));


You need to use this in place of imagettftext line you're using to impose the avatar

RealCop1993

Quote from: Dragooon on April 23, 2014, 11:12:24 AM
I did :P, does this work?
[php]$avatar imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature$avatar0000imagesx($avatar), imagesy($avatar));


You need to use this in place of imagettftext line you're using to impose the avatar

Ok so if i do like that i get white screen if i do like this


imagettftext($Signature, 20, 0, 100, 100, $COLOR_GRAY, $FONT_FIRST, $context['avatar']);
$avatar = imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature, $avatar, 0, 0, 0, 0, imagesx($avatar), imagesy($avatar));


I get web url without avatar image

"Wanting to believe the best about people doesn't make it true."

– Dr. House

Dragooon

The text is due to imagettftext($Signature200100100$COLOR_GRAY$FONT_FIRST$context['avatar']);, this will definitely not work since image is not text.

And isn't that your avatar in the image?

RealCop1993

Quote from: Dragooon on April 23, 2014, 11:36:15 AM
The text is due to imagettftext($Signature200100100$COLOR_GRAY$FONT_FIRST$context['avatar']);, this will definitely not work since image is not text.

And isn't that your avatar in the image?

Thats only singature background not avatar.
Ok so when i comment out text function i get only clean singature without url like it was


/* imagettftext($Signature, 20, 0, 100, 100, $COLOR_GRAY, $FONT_FIRST, $context['avatar']); */
$avatar = imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature, $avatar, 0, 0, 0, 0, imagesx($avatar), imagesy($avatar));


"Wanting to believe the best about people doesn't make it true."

– Dr. House

Dragooon

Is $context['avatar'] as a valid URL? Can you paste the URL? And the imagecopy function is called before imagepng/imagedestroy right?

RealCop1993

Quote from: Dragooon on April 23, 2014, 11:50:27 AM
Is $context['avatar'] as a valid URL? Can you paste the URL? And the imagecopy function is called before imagepng/imagedestroy right?

Yep, since it's called as


global $context, $settings, $modSettings, $db_prefix, $boardurl;

loadMemberData(array($korisnikov_id), false, 'profile');
loadMemberContext($korisnikov_id);

        $context['status'] = $memberContext[$korisnikov_id]['online']['text'];
  $context['avatar'] = $memberContext[$korisnikov_id]['avatar']['href'];


url of avatar should work just fine.

And here is whole part of one style when i do like you say Mr.


<?php
if (file_exists(dirname(__FILE__) . '/SSI.php')) {
require(
dirname(__FILE__) . '/SSI.php');
}
else die(
"ERROR: SSI.php nije pronaden!");


error_reporting(E_ALL);
$username=""
$password=""
$database=""
$host="localhost"

mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "ERROR: Dogodila se greska pri povezivanju na bazu podataka!");

if(isset(
$_GET['id'])) $korisnikov_id $_GET['id']; 
else if(isset(
$_POST['id'])) $korisnikov_id $_POST['id'];

$korisnikov_id mysql_real_escape_string($korisnikov_id); 

if(isset(
$_GET['stil'])) $stil $_GET['stil']; 
else if(isset(
$_POST['stil'])) $stil $_POST['stil'];
 
$stil mysql_real_escape_string($stil); 

if(
$stil == volimsamosebe) {  


$query "SELECT * FROM `balkanna_samp_members` WHERE `id_member` = '$korisnikov_id' LIMIT 1"

$rezultat mysql_query($query) or die(mysql_error());

if(
mysql_num_rows($rezultat) == "0") die("Taj korisnicki id ne postoji u bazi."); 

$row mysql_fetch_assoc($rezultat);

$t_ime $row['real_name']; 
$ime $row['member_name']; 
$postovi $row['posts']; 
$spol $row['gender']; 
$email $row['email_address']; 
$ptext $row['personal_text']; 
$ukupnovreme $row['total_time_logged_in']; 
$lokacija $row['location'];
$registracija $row['date_registered']; 
$grupe $row['id_group']; 

if(
$spol == 1$spoltext "Musko"
if(
$spol == 0$spoltext "Zensko"


global 
$context$settings$modSettings$db_prefix$boardurl;

 
loadMemberData(array($korisnikov_id), false'profile');
 
loadMemberContext($korisnikov_id);

        
$context['status'] = $memberContext[$korisnikov_id]['online']['text']; 
  
$context['avatar'] = $memberContext[$korisnikov_id]['avatar']['href']; 

  
header("Content-type: image/jpeg,image/gif,image/png"); 

$Potpisi = @imagecreatefrompng('volimsamosebe.png'); 

$BOJA_CRNA imagecolorallocate($Potpisi000); 
$BOJA_BELA imagecolorallocate($Potpisi255255255);
$BOJA_SIVA imagecolorallocate($Potpisi153153153);
$BOJA_CRVENA imagecolorallocate($Potpisi25500); 
$BOJA_LJUBICASTA imagecolorallocate($Potpisi217127219);

$FONT_PRVI "./Fontovi/MPonderosa.ttf"
$FONT_DRUGI "./Fontovi/Pricedown.ttf"
$FONT_TRECI "./Fontovi/Minecrafter_3.ttf"
$FONT_CETVRTI "./Fontovi/BPdiet.otf"
$FONT_PETI "./Fontovi/Aleo-Bold.otf";
$FONT_SESTI "./Fontovi/Aleo-Italic.otf";

$ADMINISTRATOR 'Administrator';
$COADMIN 'Co Admin';
$WEBMASTER 'Webmaster';
$SMOD 'S. Moderator';
$KORISNIK 'Korisnik';

if(
$grupe == 1
{
imagettftext($Potpisi20042538$BOJA_SIVA$FONT_SESTI$t_ime); 
imagettftext($Potpisi20042585$BOJA_CRVENA$FONT_SESTI$ADMINISTRATOR); 
}
else
{
imagettftext($Potpisi20042538$BOJA_CRNA$FONT_SESTI$t_ime); 
imagettftext($Potpisi20042585$BOJA_SIVA$FONT_SESTI$KORISNIK); 
}

imagettftext($Potpisi200425129$BOJA_SIVA$FONT_SESTI$postovi); 
imagettftext($Potpisi200425177$BOJA_SIVA$FONT_SESTI$context['status']); 



$avatar imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Potpisi$avatar0000imagesx($avatar), imagesy($avatar));

 
imagepng($Potpisi);
imagedestroy($Potpisi);

}else { die(
"ERROR: Taj stil ne postoji u bazi podataka! Pronadjeni stilovi (1) , (2) , (3) , (4) "); }

?>


"Wanting to believe the best about people doesn't make it true."

– Dr. House

Dragooon

Hm, I'm not sure. This seems to work in localhost, either the server isn't unable to access the avatar's image or something else is wrong? Can you check the value of $context['avatar']?

RealCop1993

Quote from: Dragooon on April 23, 2014, 12:10:54 PM
Hm, I'm not sure. This seems to work in localhost, either the server isn't unable to access the avatar's image or something else is wrong? Can you check the value of $context['avatar']?

Okay so this is example how do i get avatar in Index.template.php
So it's like this


<div class="avatarbaby">';
if(!empty($context['user']['avatar']))
echo '
<a href="', $scripturl, '?action=profile" title="Your Profile">'.$context['user']['avatar']['image'].'</a></center>';


Image:


Btw i just want to say thanks for all time i took you trying to resolve this :/

"Wanting to believe the best about people doesn't make it true."

– Dr. House

Advertisement: