Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Write text onto an image Jump to:  
Category: >> PHP Code >> Write text onto an image Bookmark and Share

<< lastnext >>

Snippet Name: Write text onto an image

Description: Example of how to superimpose text onto an image. Great for watermarking or for copyright info, domain tagging, etc.

Also see:
» GD barchart demo
» Simple image scaling
» Create thumbnails with PHP
» Make grayscaled image
» CAPTCHA w/ GD Image Library

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?PHP
 
// load the image from the file specified:
$im = imagecreatefrompng("image.png");
// if there's an error, stop processing the page:
IF(!$im)
{
DIE("");
}
 
// define some colours to use with the image
$yellow = imagecolorallocate($im, 255, 255, 0);
$black = imagecolorallocate($im, 0, 0, 0);
 
// get the width and the height of the image
$width = imagesx($im);
$height = imagesy($im);
 
// draw a black rectangle across the bottom, say, 20 pixels of the image:
imagefilledrectangle($im, 0, ($height-20) , $width, $height, $black);
 
// now we want to write in the centre of the rectangle:
$font = 4; // store the int ID of the system font we're using in $font
$text = "vdhri.net"; // store the text we're going to write in $text
// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*STRLEN($text) )/2;
// finally, write the string:
imagestring($im, $font, $leftTextPos, $height-18, $text, $yellow);
 
// output the image
// tell the browser what we're sending it
HEADER('Content-type: image/png');
// output the image as a png
imagepng($im);
 
// tidy up
imagedestroy($im);
 
?>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 204 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?