Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Prev Previous Post   Next Post Next
  #1  
Old 06-01-2009, 02:54 AM
Travis641's Avatar
Travis641 Travis641 is offline
 
Join Date: Nov 2001
Location: USA
Posts: 68
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Displaying Custom Profile Fields on an Image

Hello, I'm trying to set up a signature image creator for users on my website. What I want to do is have the php script, pull a profile field from the database and insert the text onto the image. I found a script to make images, however after modifying it a great deal, I still can't get this to work.

I'm able to get the page itself to display the profile field, however the image refuses to show it. The image also refuses to acknowledge I'm even logged in.

I tried
Code:
$text = $vbulletin->userinfo['field17'];
but I'm not sure that's right regardless.

This is the code for the image script:

Code:
<?php
function measure_string($s,$font,$fh,$ta)
{
    // error_log("measure_string: font ." . $font . ".", 0);
    list($blx,$bly,$brx,$bry,$trx,$try,$tlx,$tly) = imagettfbbox($fh,$ta,$font,$s);
    return max($trx,$brx) - min($tlx,$blx);
}

function measure_char($c,$font,$fh,$ta=0)
{
    $s1 = "mm";
    $m1 = measure_string($s1,$font,$fh,$ta);
    $m2 = measure_string("m" . $c . "m",$font,$fh,$ta);
    return $m2 - $m1;
}

/*
  * Given a string of text, return an array of lines
  * wrapped to fit within line_width
  */
function wrap_text($text, $font, $fontheight, $line_width)
{

    $text_angle = 0;
    $a_chars = array();
    $linelen = 0;
    $line_start = 0;
    $lastpos = 0;    
    $line = "";
    $len = strlen($text);
    for ($i = 0; $i < $len; $i++) {
        if (ctype_space($text[$i]) || ($text[$i] == "\n") || ($i == $len -1)) { // end of a word?
            if (measure_string($line, $font,$fontheight, $text_angle) >= $line_width) { // backup
                if ($lastpos > $line_start) {
                    $text[$lastpos] = "\n";
                    $line_start = $lastpos;
                    $line = substr($text,$lastpos+1, $i - $lastpos); // what if this $line is too long?
                } else {
                    // handle case of no word breaks in line > width
                    // options: punt or insert newline
                    // choice: punt
                    // this code isn't right. maybe the right thing is to just insert a newline _here_.
                    while (($text[$i] != '\n') && !ctype_space($text[$i]) && ($i < $len)) {
                        $i++;
                        $line_start = $lastpos;
                        $line = "";
                    }
                } // end if-else lastpos > line_start
            } else {
                $lastpos = $i; // not too long yet: mark end of last word seen
            }
        }
        if ($text[$i] == '\n') {
            $line_start = $lastpos;
            $line = "";
        } else {
            $line = $line . $text[$i]; // could use substr to get same effect
        }
    
    }

    $arr = explode("\n", $text);
    return $arr;
}

function wrapped_text_image($text="", $font='./fonts/verdana.ttf', $fontheight=16, $color=0xffff00, $bgcolor=0x808080, $width=480, $shadow="no", $border="yes", $bordercolor=0xdedede, $transbg="no" )
{
//    $old_level = error_reporting(6143); //E_ALL

    error_log("Wrapping text '$text'");
    
    $height = 30;
    $textangle = 0;
    
    $v_pad = 6; // pad at top and bottom of image
    $h_pad = 15; // pad at left and right, original is 5

    $line_pad = 6; // pad with each line

    $image = null;

    /* measure a character */
    $textangle = 0;
    list($pos_blx, $pos_bly, $pos_brx, $pos_bry, $pos_trx, $pos_try, $pos_tlx,
        $pos_tly) = imagettfbbox($fontheight, $textangle, $font, "Mg");

    $em_height = $pos_bly - $pos_tly;

    $line_height = $em_height + $line_pad;
    $line_width = $width - $h_pad * 2;

    $arr = wrap_text($text, $font, $fontheight, $line_width);

    $height = $v_pad * 2 + sizeof($arr) * $line_height + 35; //35 to add extra space at bottom!

    /*
    // if only one line, calculate width, otherwise use passed-in width
    if (sizeof($arr) == 1)    // remove it to create fixed witdh even if just 1 line!!
    {
        list($blx, $bly, $brx, $bry, $trx, $try, $tlx, $tly) = 
            imagettfbbox($fontheight, $textangle, $font, $text);
        $width = $brx - $blx + $h_pad*2;
    }
    */

    $image = imagecreate($width, $height);
    $red = ($bgcolor & 0xff0000) >> 16;
    $green = ($bgcolor & 0x00ff00) >> 8;
    $blue = $bgcolor & 0x0000ff;

    if($transbg == "yes"){
        imagecolorallocatealpha($image, $red, $green, $blue, 127); // background color + 127 is transparent!!
    } else {
        imagecolorallocate($image, $red, $green, $blue); // background color
    }

    $red = ($color & 0xff0000) >> 16;
    $green = ($color & 0x00ff00) >> 8;
    $blue = $color & 0x0000ff;

    $textcolor = imagecolorallocate($image, $red, $green, $blue);
    
    //text shadow
    $shadowcolor = imagecolorallocate($image, 193, 193, 193);
    
    if($border == "yes"){
        //border color
        $red = ($bordercolor & 0xff0000) >> 16;
        $green = ($bordercolor & 0x00ff00) >> 8;
        $blue = $bordercolor & 0x0000ff;
        $bordercolors = imagecolorallocate($image, $red, $green, $blue);
        //$bordercolors2 = imagecolorallocate($image, 222, 222, 128);
        
        //border
        $x = 0;
        $y = 0;
        $w = $width - 1;
        $h = $height - 1;
        imageline($image, $x,$y,$x,$y+$h,$bordercolors); //left
        imageline($image, $x,$y,$x+$w,$y,$bordercolors); //top
        imageline($image, $x+$w,$y,$x+$w,$y+$h,$bordercolors); //right
        imageline($image, $x,$y+$h,$x+$w,$y+$h,$bordercolors); //bottom
        //end border
    }

    $line_x = $h_pad;
    $line_y = $line_height /* +  $line_pad*/ + 10; // 10 is extra padding

    foreach ( $arr as $s )
    {
        if($shadow == "yes") { //shadow generated by double image with different axis and color
        imagettftext($image, $fontheight, $textangle, $line_x + 2, $line_y + 2, $shadowcolor, $font, $s);
        }
        
        imagettftext($image, $fontheight, $textangle, $line_x, $line_y, $textcolor, $font, $s);
        $line_y = $line_y + $line_height; 
    }
    
    // put some stuff in to make it hard to ocr the text
//    $w = 0;
//    for ($w = $width, $h = $height; $w > 0 && $h > 0; $w = $w - $width / 5, $h = $h - $height / 5)
//        imageellipse($image, $width/2, $height/2, $w, $h, $textcolor);

//    error_reporting($old_level);

    return $image;
}

function show_image($image)
{
    header("Content-type: image/png");
    imagepng($image);
}

// generate and show the image, then destroy it.
function get_image($text, $font="bookos.ttf", $fontheight=16, $color=0, $bgcolor=0xffffff, $width=480 )
{
    $image = wrapped_text_image($text, $font, $fontheight, $color, $bgcolor, $width);
    if ($image) {
        show_image($image);
        imagedestroy($image);
        return true;
    } else {
        return false;
    }
}

?>
Any help is appreciated.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07883 seconds
  • Memory Usage 2,511KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete