Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:19:31+00:00 2026-06-11T09:19:31+00:00

I need some help about PHP GD. Here is my piece of code. header(Content-type:

  • 0

I need some help about PHP GD. Here is my piece of code.

    header("Content-type: image/gif");

    $image = imagecreatetruecolor(550, 20);
    imagealphablending($image, false);

    $col=imagecolorallocatealpha($image,255,255,255,127);
    $black = imagecolorallocate($image, 0, 0, 0);

    imagefilledrectangle($image,0,0,550,20,$col);
    imagealphablending($image, true);

    $font_path = 'font/arial.ttf';
    imagettftext($image, 9, 0, 16, 13, $black, $font_path, $lastlisten);
    imagesavealpha($image, true);

    imagepng($image);

The problem is when I use imagepng, it can show the png just fine like this. enter image description here

But if I use imagegif instead, it will become this.
enter image description here

I did tried using different header for gif and png. The result for imagegif is still the same.
The question is how do I make in order to display GIF version properly? Thanks you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:19:33+00:00Added an answer on June 11, 2026 at 9:19 am

    First problem : your characters are ugly: that’s because you need to set a palette with less colors when using imagecreatetruecolor.

    $image = imagecreatetruecolor(550, 20);
    imagetruecolortopalette($image, true, 256);
    

    should solve this problem.

    Second problem : there is no transparency.

    As you can see on PHP manual,

    imagesavealpha() sets the flag to attempt to save full alpha channel
    information (as opposed to single-color transparency) when saving PNG
    images.

    This function does not work with GIF files.

    You can use imagecolortransparent instead but this will not be perfect because fonts has anti-aliasing to make their border sweeter.

    Here is my code:

    <?php
    
    $lastlisten = "test test test test test test";
    
    error_reporting(E_ALL);
    header("Content-type: image/gif");
    
    $image = imagecreatetruecolor(550, 20);
    imagetruecolortopalette($image, true, 256);
    
    $transparent=imagecolorallocatealpha($image,255,255,255,127);
    imagecolortransparent( $image, $transparent);
    imagefilledrectangle($image,0,0,550,20,$transparent);
    
    $black = imagecolorallocate($image, 0, 0, 0);
    $font_path = dirname(__FILE__) . '/font.ttf';
    imagettftext($image, 9, 0, 16, 13, $black, $font_path, $lastlisten);
    
    imagegif($image);
    

    Result here

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with PHP Class. I have limited knowledge about how it
I need some help about WCF and authorization. Currently I have a client which
I need some help about RegExp in AS3. I have a simple pattern :
I'm no php expert (a mere beginner) but need some help! After hours searching
I need some consultation here. I am a C# developer, and for just about
I'm working with some php and need some help. Basically I have a script
I need some help about mod_rewrite, this is my wordpress address: http://localhost/my_v2010/restaurants?m=display_Add base_url: http://localhost/my_v2010/
I'm a beginner here and need help. I have this code, which works and
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help with Activerecord Querying in a has_many :through association. Model: Job class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.