473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
Dec 13 '06 #1
3 7353
>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.

Dec 13 '06 #2
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!
Dec 13 '06 #3
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/functio...drectangle.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);
?>

Dec 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: joes | last post by:
Hello there ! I rendering a PDF with XSLT using Xalan and FOP. I like to place in my article an image, so that the text is floating around the image. I tried several things but it didn't work so...
3
by: Xerxes | last post by:
Hi, I need help in setting up a page where the text wraps around an image. Right now, I am using table, with text in one <td> and the image in the adjacent <td>. The problem is when the text is...
2
by: Macsicarr | last post by:
Hi All Wonder if you could help me. I have created a CMS system that allows the user to enter text and pic 'tags' for their own About us page, eg text.... text.... text.... text.......
2
by: Jiri Palecek | last post by:
I have a question on web authoring (probably HTML+CSS). Is it somehow possible to put two words above each other inside a paragraph so the result would be valid and render at least in Mozilla? I...
4
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
3
by: jweinberg1975 | last post by:
I would like for users to be able to select from a small number of options that come from a little drop down menu which then closes. .....
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file....
10
by: bluemountain | last post by:
Hi there, Iam new to python forms and programming too I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.