CoderZone.org

Category: >> PHP Code >> Convert text to image in php Bookmark and Share

<< lastnext >>

Snippet Name: Convert text to image in php

Description: Here's how to style a text string and convert it to a transparent .PNG (alpha BG).

Also see:
» Convert Minutes to Days, Hours, an...
» Simple image resize on mouseover
» Resize and convert an image to a P...
» Analyze a remote image with PHP
» Convert RGB to Hex with ASP
» Convert a String to Title Case in ...
» Convert Extensions To Lowercase
» Tabs-To-Space Converter
» Convert Unix time string to a date...
» Convert Dollars And Cents Value to...
» LDAP Timestamp Converter
» Convert entities into normal chara...
» BR2NL Function - Opposite of NL2BR
» Convert Seconds to Hours:Minutes:S...
» Saving Remote Images With PHP
» Truncate text while preserving HTM...
» Convert UK Dates To mySQL Format D...
» Convert miles to feet, feet to mil...
» Converting Rows to Columns
» Random Image from Directory
» CONVERT
» Convert text to soundex
» Convert between Decimal, Binary, O...
» Convert LONGs to LOBs
» Convert Minutes to Hours
» Convert Hours to Minutes
» Simple image scaling
» Show current time as PNG-image
» Check if an image exists (GD)

Comment: (none)

Author:
Language: PHP
Highlight Mode: PHP
Last Modified: December 20th, 2010

// Set the content-type
header('Content-type: image/png');
 
// Create the image
$im = imagecreatetruecolor(400, 30);
 
// Create a few colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
 
// set the text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
 
// Add a shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
 
// And add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
 
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 4