Jump to content

Colors while creating an image.


tc48

Recommended Posts

Hello,

I am dynamically creating an image with this code

$badge = imageCreate(450,120);
$resource="../images/covers/212.jpg";
$resourcepic=@imagecreatefromjpeg($resource);

imageColorAllocate($badge, 255, 255, 255);
$whitetextcolor=imageColorAllocate($badge, 255, 255, 255);
$blacktextcolor=imageColorAllocate($badge, 0, 0, 0);
$siderectcolor= imageColorAllocate($badge, 0, 104, 163);
$gothicbfontfile="../../fonts/gothicb.ttf";
$impactfontfile="../../fonts/gothic.ttf";
imagefilledrectangle ($badge, 0, 0, 20, 120, $siderectcolor );
imagefilledrectangle ($badge, 448, 0, 451, 120, $siderectcolor );
imagefilledrectangle ($badge, 0, 0, 450, 1, $siderectcolor );
imagefilledrectangle ($badge, 0, 118, 450, 120, $siderectcolor );
$text="TEXTHERE";
imagettftext ( $badge, 12, 90, 15, 118, $whitetextcolor, $gothicbfontfile, $text );
imagettftext ( $badge, 10.0, 0, 320, 40, $blacktextcolor, $impactfontfile, "$firstname $lastname");
imagettftext ( $badge, 10.0, 0, 150, 40, $blacktextcolor, $impactfontfile, "$traveldate");
imagettftext ( $badge, 11, 0, 145, 20, $blacktextcolor, $gothicbfontfile, $title);

for($i=1;$i<=4;$i++){
$ylocation=60+(14*($i-1));
imagettftext ( $badge, 9.0, 0, 200, $ylocation, $blacktextcolor, $impactfontfile, "$org[$i] $dest[$i]");

}
for($i=5;$i<=8;$i++){
$ylocation=60+(14*($i-5));
imagettftext ( $badge, 9.0, 0, 300, $ylocation, $blacktextcolor, $impactfontfile, "$org[$i] $dest[$i]");

}
imagecopy ( $badge, $resourcepic, 30, 17,  0, 0,  111, 83 );
Imagejpeg($badge,"badge.jpg",100);
ImageDestroy($pic);

 

The problem is that the image appears to be comprised of shades of just a few different colors, instead of being smooth.  It kind of looks like a GIF with maybe about 4 different colors.

 

Thanks for your help

Link to comment
Share on other sites

Ok nevermind I just used imagecreatetruecolor() instead.  Now my next question is, is there any type of anti-aliasing that I can apply to the text in the image? It all looks kind of rough.  Thanks

Link to comment
Share on other sites

here is what the generated image looks like...

 

<img src="http://www.airpinions.com/members/images/badges/231.jpg">

 

Notice how the text looks all shaky n theres noise around the white lettering on the left, and the click to view.

The click to view is originally pulled from here..

 

<img src="http://www.airpinions.com/images/clicktoview.jpg">

 

which you can see is clean and without artifacts.

Link to comment
Share on other sites

First, make it a PNG.  That will get rid of the artifacts. 

 

With a font of that size, anti-aliasing might not be the best idea.  If the font is small (like 10-14 pt.), then anti-aliasing does not give the best results.

 

Personally, I would just make the font 16-18 pt. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.