f



add text on top of PNG

Hi all,

not sure if this is possible in PHP - every couple of weeks; i get a few png
files; which i th open in an image editor; add a text box with comments in
the top right corner; save the pngs and save them for later use by a php
script.
My question is there an automatic way so that a php script can do all this
image editing for me ?

i appreciate all replies.

kind regards

T


0
toffee (14)
12/13/2006 12:54:42 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

3 Replies
371 Views

Similar Articles

[PageSpeed] 1

>not sure if this is possible in PHP - every couple of weeks; i get a few png
>files; which i th open in an image editor; add a text box with comments in
>the top right corner; save the pngs and save them for later use by a php
>script.
>My question is there an automatic way so that a php script can do all this
>image editing for me ?

I believe that the netpbm package can do the image editing you want,
given a PNG image of a certain size and text you want in the corner.
A shell script certainly could.  If you invoke the shell script via
PHP exec(), you could do it.  PHP can also handle things like
uploading the image files and the text.

0
12/13/2006 1:11:39 AM
toffee wrote:
> 
> Hi all,
> 
> not sure if this is possible in PHP - every couple of weeks; i get a few png
> files; which i th open in an image editor; add a text box with comments in
> the top right corner; save the pngs and save them for later use by a php
> script.
> My question is there an automatic way so that a php script can do all this
> image editing for me ?
> 
> i appreciate all replies.

Sure.

Check the image functions in the PHP manual, especially the functions
imagecreatefrompng to load a png image, imagestring (or imagepstext or
imagettftext if you want Postscript Type 1 or Truetype fonts) to write
your text into it and imagepng to output it again in png format.

Bye!
0
12/13/2006 1:19:31 AM
Anonymous wrote:
> toffee wrote:
> >
> > Hi all,
> >
> > not sure if this is possible in PHP - every couple of weeks; i get a few png
> > files; which i th open in an image editor; add a text box with comments in
> > the top right corner; save the pngs and save them for later use by a php
> > script.
> > My question is there an automatic way so that a php script can do all this
> > image editing for me ?
> >
> > i appreciate all replies.
>
> Sure.
>
> Check the image functions in the PHP manual, especially the functions
> imagecreatefrompng to load a png image, imagestring (or imagepstext or
> imagettftext if you want Postscript Type 1 or Truetype fonts) to write
> your text into it and imagepng to output it again in png format.
>
> Bye!


With a little practice it's not too tough to do this dynamically. Here
are the most useful php functions to get started with...

http://us2.php.net/imagecreatefrompng
http://us2.php.net/manual/en/function.imagefilledrectangle.php
http://us2.php.net/manual/en/function.imagefttext.php

Here's a simple example so you can get an idea of what is involved....

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = ImageCreateFrompng("images/myImg.png");

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 10, 5, 450, 80, $white);

// The text to draw
$text = 'Dynamic Text';
// Replace path by your own font path
$font = 'fonts/arial.ttf';

// Add some shadow to the text
//imagettftext($im, 30, 45, 201, 301, $grey, $font, $text);

// Add the text
imagettftext($im, 15, 10, 410, 70, $grey, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

0
pangea1013 (26)
12/13/2006 3:43:20 AM
Reply: