Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts

    Dynamic rotated text

    Hi guys,

    Some time ago I did some research on how to actually rotate some text on a webpage - a static image wasn't a solution as the text needed to be dynamic (in this example's and my case a date function). I was not able to find anything 'easy' with cross-browser support, so I worked out this script - some of it partly copied from other sites while some of it is modified on my own.

    The script will generate a dynamic image with transparent background with the current date, a specified font and rotate it - the input and properties can of course be modified.

    Paste the below in a file called image.php
    Edit the "font" paths to reflect your fonts.
    Display the image by following:

    Code:
    <img src="image.php" alt="Your ALT Text" />
    PHP Code:
    <?php 
    // Defines the content as an PNG image
    header("Content-type: image/png"); 

    // Creates the image - edit those properties in order to change rotation and font types. I have defined two different fonts
    $image imagecreate(7570);
    $degrees 40;
    $font 'fonts/Jerry_B4s_handwriting.ttf';
    $font1 'fonts/verdana.ttf';

    // transparent color
    $transparent_color imagecolorallocate($image00000);

    // set the transparent color
    imagecolortransparent($image$transparent_color);

    // fill the image with our transparent color
    imagefilledrectangle($image,0,0,119,119,$transparent_color); 

    //imagecolorallocate($image, R, G, B) in HEX values
    $font_black imagecolorallocate($image218);

    //EDIT those strings to output YOUR text
    //outputs day
    $string_day date("l");          
    //outputs month, date
    $string_rest date("F d");  
    //outputs year
    $string_year date("Y"); 


    //($image, fontsize, angle(use a combination of this and the $degrees variable),  rightident(x), downindent(y), textcolor, font, data) 
    imagettftext($image13, -251020$black$font$string_day);
    imagettftext($image10, -251040$black$font1$string_rest);
    imagettftext($image9, -201060$black$font1$string_year);

    $rotate imagerotate($image$degrees,0);
    //Preserves transparency 
    imagealphablending($rotatetrue); 
    imagesavealpha($rotatetrue);

    imagepng($rotate); 
    imagedestroy($image);
    ?>
    The above will generate an image like the attachment.
    'Unfortunately' I havn't found a way to get rid of the grunge look of the text though.
    Attached Thumbnails Attached Thumbnails Dynamic rotated text-date.png  

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    try to create a bigger picture, 2-3 times bigger, and after you finish scale to actual size. Maybe will work,

    best regards

  • #3
    New Coder
    Join Date
    Jun 2009
    Location
    Bangalore, India
    Posts
    42
    Thanks
    3
    Thanked 4 Times in 4 Posts
    I think the grunge look of the text is, in a way, a good thing.

    With slight modifications, you can make this a captcha script (and sell it too! ) All it needs is random text and a few random pixels/lines/rectangles/circles...

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    You can't sell any scripts nowadays, PHP is so common, theres a free script for everything
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #5
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    there is not!

  • #6
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    There almost is ;]
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]


  •  

    Posting Permissions

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