AW: [PHP-WIN] GD, write text on image

From: Date: Wed, 23 Apr 2003 16:43:11 +0000
Subject: AW: [PHP-WIN] GD, write text on image
Groups: php.windows 
Request: Send a blank email to php-windows+get-19578@lists.php.net to get a copy of this message
Hi, I once had a similar problem. It was easier in that the whole image was generated in the fist place so the control over color and position of the text could be managed on a relatively high level. It seems the solution to your problem depends on the kind of images you want a legend to put on. Your add-and-divide idea can be made quite fast: If contrast is not too heavy it might be enough to check some five or so pixels per letter one after the other. Then set a threshold, let's say 97 to 255 is getting black letters and 0 to 153 is getting black letters (experiment with a continuous grayscale, the best triggers are most probably not symmetric to 127 !). This is not to get every second letter in a different color with images at average brightness. If the text shall be completely black or white you might want to just examine some three lines of pixels in the areas where the text could go, thereby checking out whitch area is bright or dark with best (lowest) contrast in it (least squares). Looking at2-3 pixels per letter in the line should be enough. That should not be too expensive. I'd prefer the first approach (taking the pixels randomly !) if it is not quite sure the area for the text is stable enough with respect to brightness. -- Sven > -----Ursprüngliche Nachricht----- > Von: Bernhard Döbler [SMTP:programmer@bardware.de] > Gesendet am: Mittwoch, 23. April 2003 16:36 > An: php-windows@lists.php.net > Betreff: [PHP-WIN] GD, write text on image > > Hi, > > I'm going to write some text on an image. My problem is, if the background is to bright I cannot read the text if it's white. If I use black as the text-color I cannot read it, if the background is to dark. > Hence I'm looking for a way to either determine the darkest corner of the picture to write white text into (dimensions of the "corner" are counted by imagettfbbox), or a way to determine the brightness of the defined corner and dependend on the darkness use black or white text. > > I wonder if someone has ever done this. I could of course take the box to write the text into, add each pixel's color and divide by the number of the pixels or something like that, but I'm sure it's not a fast way. > > Have you ever argued about text you wrote on an image and could not read because of the background? > > Thanks, > Bernhard > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.windows (#19578) next »