473,320 Members | 1,949 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,320 software developers and data experts.

imagecolorallocate - No Effect

I'm having trouble with the imagecolorallocate function. I'm creating
a security image, and the color of the text changes depending on the
background for some reason (ie, for one background the text is always
black, one is always pink, and the other is always yellow).

Any ideas? I'm running Freebsd.

Here's my code:

<?php

include_once('session.php');
include_once('functions.php');

$strCode = randomcode(6);
$_SESSION['strCode'] = $strCode;

$bgdir = 'images/verification/';
$bgs = array('bg1.png', 'bg2.png', 'bg3.png');
$im = ImageCreateFromPNG($bgdir.$bgs[rand(0, count($bgs)-1)]);

$font = '/usr/X11R6/lib/X11/fonts/urwfonts-ttf/n021003l.ttf';

$size = rand(12, 16);
$angle = rand(-5, 5);
//$color = ImageColorAllocate($im, rand(0, 50), rand(0, 50), rand(0,
50));
$color = imagecolorallocate($im, 0, 0, 0);

$textsize = imagettfbbox($size, $angle, $font, $strCode);
$twidth = abs($textsize[2]-$textsize[0]);
$theight = abs($textsize[5]-$textsize[3]);
$x = (imagesx($im)/2)-($twidth/2)+(rand(-20, 20));
$y = (imagesy($im))-($theight/2);

imagettftext($im, $size, $angle, $x, $y, $color, $font, $strCode);

header("Content-Type: image/png");
imagepng($im);

imagedestroy($im);

exit;

?>

Thanks,
Mike

Apr 6 '06 #1
5 2214

I couldn't reproduce this. The text was always black for me, as
expected due to the imagecolorallocate($im, 0, 0, 0).

I'm developing on Mac OS X using Safari web browser so maybe it's
something specific with FreeBSD or your web browser?

Apr 7 '06 #2
Thanks for trying it out. Last night I resolved the problem by changing
the resolution of the background png images. Does the
imagecolorallocate use the color pallette of the image resource you
give it?

Mike

Apr 7 '06 #3
Looking at the documentation
(http://uk2.php.net/manual/en/functio...orallocate.php) it seems
to imply that it does use the color pallette of the image resource.
From documentation: "imagecolorallocate() must be called to create each

color that is to be used in the image represented by image."

Apr 7 '06 #4
This is as confusing as legal documentation. :)

But thanks... that must be what happenned. 0,0,0 must have been light
pink and light yellow in my first, low-quality png's pallettes.

Mike

Apr 7 '06 #5

I'm glad you found the documentation confusing as well. I thought I
was just being thick ;o)

Apr 8 '06 #6

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

Similar topics

0
by: Neal | last post by:
Using the GD library, I'm having a bit of difficulty getting imagecolorallocate() to work as I would expect it to. Using a call of $color = imagecolorallocate ($image, 255, 0, 0); (after...
2
by: Susanna | last post by:
Hi all, I'm using the following slideshow script that I found on the web to display changing images with a crossfade effect. Eventually I will be adding many more images to the slideshow. The...
7
by: Gary Duncan | last post by:
Hi all, My first incursion into this group so apologies if the following question is misplaced. That is, I'm trying to find some free javascript which implements the "ken burns effect" on...
14
by: Charles Douglas Wehner | last post by:
If you go to http://www.netscape.com and search for Wehner, you will find my site. It will say http://wehner.org You click to preview, and find that my home page is too big for the preview...
16
by: eholz1 | last post by:
Hello CSS group, I saw a beautiful effect that I would like to use either by CSS or using photoshop to create the image/effect (maybe even imagemagick) the site address is:...
3
by: Beamer | last post by:
Hi I am trying to build a roating slide effect in javascript. Basically, I have a list like below <ul id="slideShowCnt"> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li...
3
by: Gandalf | last post by:
Sharp effect is one of the photoshop effect on letters. some one a javascript script that create the same effect? thanks
7
by: nolo contendere | last post by:
the alert message appears before the Effect.SlideUp even begins. How can I ensure that the SlideUp completes before executing the next statement? I've tried setTimeout, and I can kind of get it to...
2
by: AndrewC | last post by:
I am using the Scriptaculous/Prototype libraries to build a project and I really want to have an effect like the mootools download page (http://www.mootools.net/download) where when you mouse over...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.