WordPress.org

Ready to get started?Download WordPress

Forums

How to create dynamic signature with my last post title (9 posts)

  1. alien13
    Member
    Posted 4 years ago #

    Hi, I want to create dynamic image, that can use for signature in forums and etc. I want script that create image with last post title. I found this script, that create image with my custom text, but I dont know how to change SOME TEXT with last post title from my blog. I really need help, thanks in advance!

    <?php
    $my_img = imagecreate( 200, 80 );
    $background = imagecolorallocate( $my_img, 0, 0, 255 );
    $text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
    $line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
    imagestring( $my_img, 4, 30, 25, "<strong>SOME TEX</strong>T",
      $text_colour );
    imagesetthickness ( $my_img, 5 );
    imageline( $my_img, 30, 45, 165, 45, $line_colour );
    
    header( "Content-type: image/png" );
    imagepng( $my_img );
    imagecolordeallocate( $line_color );
    imagecolordeallocate( $text_color );
    imagecolordeallocate( $background );
    imagedestroy( $my_img );
    ?>
  2. s_ha_dum
    Member
    Posted 4 years ago #

    This is kindof a clever idea. You'll need to query the wp_posts table for the most recent title. There are different ways to do this depending on where you put the script. I'd guess you'd want to require_once('path/to/wp-config.php'); and then use $wpdb to grab the title of the most recent post.

  3. alien13
    Member
    Posted 4 years ago #

    I dont understand php so much, is there way to help me with code?

  4. whooami
    Member
    Posted 4 years ago #

    Like this? super old :)

    I wouldnt bother with a query for that.

  5. s_ha_dum
    Member
    Posted 4 years ago #

    That looks like it, whooami, but what about the code to generate it?

    I guess you could read an RSS feed instead of query the DB, but you've got to get the last post title from somewhere.

  6. whooami
    Member
    Posted 4 years ago #

    For mine: the title of my last post gets written to a plain text file, and then is feed into a very similar script to above that i wrote.

    Im sorry, I dont share code running on my site here. generic example of how you could do it below, though.

    You could just as easily parse the feed, sure, but I think my code is less bytes :)

    hook into this:

    http://adambrown.info/p/wp_hooks/hook/wp_insert_post

    $sigpost = $_POST['post_title'];
    $fp = fopen("yourfilename","w");
    $str = $sigpost;
    fwrite ($fp,$str);
    fclose($fp);
    `
    then you read that into an edited version of the script above.

  7. alien13
    Member
    Posted 4 years ago #

    Thats good idea whooami, but how to make the script above to read first line of some file.

  8. whooami
    Member
    Posted 4 years ago #

    its more than a good idea -- its my idea :)

    but how to make the script above to read first line of some file.

    edit the script -

    fwiw, there are examples of what you just asked for all over the web. How do you think that church sign thing works?

  9. whooami
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic