PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] How can I convert PNG to GIF keeping the transparency?

 July 18, 2022     delphi, gif, graphics, png     No comments   

Issue

How can I convert PNG to GIF keeping the transparency?

I would have hoped that using the Assign( ) method would work but it doesn't seem to migrate transparency. In the GIF, it's represented as black.

    png:=TPngImage.Create;
    try
      png.LoadFromFile(sFile);
      // comes from file:  png.TransparencyMode;
      // comes from file:  png.Transparent

      // didn't help:  gif.Transparent:=true;

      gif.Assign(png);

      // didn't help:  gif.Transparent:=true;

      gif.SaveToFile('e:\tmp\out.gif');
    finally
      png.Free;
    end;

I haven't found a way to handle this in Delphi...

thanks!


Solution

It is possible to transfer an image from a PNG to a GIF. However, I don't recommend that you do so. The GIF format is substantially less capable than PNG. PNG supports RGBA color channels and partial transparency. GIF uses a 256 color palette and no support for partial transparency.

There are many libraries available that will make the best of a bad job and attempt to produce a GIF image that is close to the PNG image, but information will be lost.

The GIF format dates from the late 1980s and time has moved on. It has long since served its purpose. PNG is modern, capable and well supported. If it is possible to do so you should switch from GIF to using PNG.



Answered By - David Heffernan
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing