Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: RealCop1993 - huhtikuu 23, 2014, 10:08:34 AP

Otsikko: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 10:08:34 AP
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. :)
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: Dragooon - huhtikuu 23, 2014, 10:19:00 AP
imagettftext($Singature, 20, 0, 100, 100, $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, $avatar, 0, 0, 0, 0, imagesx($avatar), imagesy($avatar));
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 10:34:24 AP
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 10:19:00 AP
imagettftext($Singature, 20, 0, 100, 100, $BOJA_SIVA, $FONT_SESTI, $context['avatar']);
Wait, wouldn't this impose avatar's URL?

Exactly!

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fzaslike.com%2Ffiles%2Fu3ntfzb1urtr7m1zg1.png&hash=a4143877d69174c2ae9ef4bd1455fe3db12f43b1)

I have try that way and it's not working
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 10:19:00 AP
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
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: Dragooon - huhtikuu 23, 2014, 10:51:33 AP
You need to use imagecreatefromstring/imagecreatefrompng and imagecopy. Check out their function reference
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 11:11:09 AP
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 10:51:33 AP
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
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: Dragooon - huhtikuu 23, 2014, 11:12:24 AP
I did :P, does this work?
[php]$avatar = imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature, $avatar, 0, 0, 0, 0, imagesx($avatar), imagesy($avatar));

You need to use this in place of imagettftext line you're using to impose the avatar
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 11:26:23 AP
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 11:12:24 AP
I did :P, does this work?
[php]$avatar = imagecreatefromstring(file_get_contents($context['avatar']));
imagecopy($Signature, $avatar, 0, 0, 0, 0, imagesx($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
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fzaslike.com%2Ffiles%2F06k1rqmp10rs2q9lqot0.png&hash=b40b324a10c4f3a74c65d7e31ac9896a88434f06)
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: Dragooon - huhtikuu 23, 2014, 11:36:15 AP
The text is due to imagettftext($Signature, 20, 0, 100, 100, $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?
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 11:47:30 AP
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 11:36:15 AP
The text is due to imagettftext($Signature, 20, 0, 100, 100, $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));

Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: Dragooon - huhtikuu 23, 2014, 11:50:27 AP
Is $context['avatar'] as a valid URL? Can you paste the URL? And the imagecopy function is called before imagepng/imagedestroy right?
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 11:57:32 AP
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 11:50:27 AP
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) "); }

?>

Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: Dragooon - huhtikuu 23, 2014, 12:10:54 IP
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']?
Otsikko: Re: Can't get avatar shows up as image?
Kirjoitti: RealCop1993 - huhtikuu 23, 2014, 12:22:26 IP
Lainaus käyttäjältä: Dragooon - huhtikuu 23, 2014, 12:10:54 IP
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:
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fzaslike.com%2Ffiles%2Fm7oxkggax1x13yhkys4.png&hash=43016a282d1d18d9b5dcdcab6bdca1405728ff53)

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