• 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 );
    ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.

    Thread Starter alien13

    (@alien13)

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

    Like this? super old ??

    I wouldnt bother with a query for that.

    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.

    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:

    https://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.

    Thread Starter alien13

    (@alien13)

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

    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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to create dynamic signature with my last post title’ is closed to new replies.