Results 1 to 4 of 4

Thread: PHP Button Generator Script -Help!

  1. #1
    Join Date
    Jun 2008

    PHP Button Generator Script -Help!

    I am working on a PHP button generator.
    There will be a selection of buttons (images) and fonts. Users will be able to create an image button.

    I would like to make the button image stretch to match the length of the text string... or to at be length adjustable by the user.

    So far this works without the stretch:

    Here is the PHP thus far:
    PHP Code:
    // Set the content-type
    header('Content-type: image/png');

    // Create the image
    $im imagecreatefrompng("images/button1.png");

    // Create some colors
    $white imagecolorallocate($im255255255);
    $grey imagecolorallocate($im128128128);
    $black imagecolorallocate($im000);

    // The text to draw
    $text $_POST['label'];
    // Replace path by your own font path
    $font 'fonts/arial.ttf';

    // Add some shadow to the text

    // Add the text

    // Using imagepng() results in clearer text compared with imagejpeg()
    The HTML is:
    HTML Code:
    <form name="form1" method="post" action="buttonmaker.php">
    <input type="text" name="label" title="Enter your text here" style="font-size:16px; color:#0000FF; text-decoration:none;" value="Your text here" onfocus="if(this.value=='Your text here'){this.value=''};" onblur="if(this.value==''){this.value='Your text here'};" size="25" class="textbox">
    <input type="submit" value="Generate Button" />
    I'm thinking that the best solution would be to use three images... a left side of the button with rounded edges, a center that is stretchable, a right side with rounded edges. The left and right side images will not stretch.
    Any ideas?

  2. #2
    Join Date
    Apr 2007
    Without knowing the width of each letter for each font and font size you can't know how wide to make the button.

    You could use a create interface that allow a user to type the text in the chosen font then with javascript increase the button until it fit then post the values back to php to create the button.

    You might be able to track the width of a div or span with javascript and have the message echo inside the div using onkeydown/up. So the user writes it in the text input and they get a live display of how the button will look. The width of the div would be the middle part plus you two rounded ends caps equals the width to hand to the image generation functions.

    It looks like you have the PHP part down. You might want to take your question to the Javascript forum to see if someone there can help.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  3. #3
    Join Date
    Apr 2007
    So I was thinking about how to do this and I think I worked it out

    PHP Code:
        //process the posted info to generate your image
    <script language="JavaScript">
    function writetocell(){
            document.getElementById("wordswidth").value=document.getElementById("buttondiv").offsetWidth;//assign width to form element
    <form id="input" method="post">
    <input type="text" name="words" id="words"  onkeyup="writetocell()"><br>
    <br />
    Button preview : 
    <span style="padding:0;border:0;width:10px;background-color:#ceffce;"></span><?//add left end cap image?>
    <span id="buttondiv" style="white-space: nowrap;background-color:#cecece;"></span><?//add button background image?>
    <span style="padding:0;border:0;width:10px;background-color:#ceffce;"></span><?//add right end cap image?>
    <br /><br />
    <input type="text" name="wordswidth" id="wordswidth"  style="width:30px;"><?//make hidden input type?>
    <input type="submit">
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  4. #4
    Join Date
    Jun 2008

    Moving the goalpost... :) :)

    You know, a funny thing happened with this post... I did not use it for the original script that I was working on, but have found a use for it elsewhere and am in the process of making a "Sliding Door Sprite Generator" using this neat little script.

    I have also tried using it in a policy generator here:


    What I would like it to do is to add the text to multiple cells. That is, the company name appears about 15 times in a policy, and I would like them all to be updated when a user types the company name into the input field.
    This script works great, but only for a single <span> tag... how can I make it do multiple tags?

    Privacy Policy Generator

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.13732 seconds
  • Memory Usage 2,879KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates