Link to home
Start Free TrialLog in
Avatar of drama22
drama22

asked on

Convert Jpg /PNG To GIF

i have this idhttp code that download images to memory stream and save it on disk

i want to convert jpeg images and png to GIF then save them to disk

if (itsimage = 'image/jpeg') or (itsimage = 'image/png') or (itsimage = 'image/gif') then
begin
try
aIdHttp.Get(trim(FURL), aMs);
except
end;
aMs.SaveToFile(path);
end;

try
if aIdHttp.Connected then
aIdHttp.Disconnect;

except // do not care about any errors yet, maybe log them later

end;

Open in new window

Avatar of pepr
pepr

If you really need to do it in Delphi, the best for you would be to ask at some Delphi forum. The reason is that it has some specialized libraries/classes, so there is a kind of native-for-Delphi way to do it. The following link is just example

http://www.delphipages.com/forum/showthread.php?t=173904

If you need more complex image transformations, then try ImageMagick -- free software product (http://www.imagemagick.org/) that gives you both ready to be used utilities (executables) to do the transformations from command line, and also libraries that can be linked to your program in many programming languages, Pascal being one of them (from the page):
Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), L-Magick (Lisp), Lua (LuaJIT), NMagick (Neko/haXe), Magick.NET (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images dynamically and automagically.
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of drama22

ASKER

i tried

function JpgToGif(ms: TMemoryStream): Boolean;
var
  gif: TGIFImage;
  jpg: TJPEGImage;
begin
  Result := False;

  gif := TGIFImage.Create;
  try
    jpg := TJPEGImage.Create;
    try
      //jpg
      ms.Position := 0;
      jpg.LoadFromStream(ms);
      jpg.DIBNeeded;
      gif.Assign(jpg);

      //save...
      ms.Clear;
      gif.SaveToStream(ms);
      Result := True;
    finally
      jpg.Free;
    end;
  finally
    gif.Free;
  end;
end;

Open in new window



if (itsimage = 'image/gif') then
begin
try
aIdHttp.Get(trim(FURL), aMs);
except
end;
aMs.SaveToFile(path);
end else if (itsimage = 'image/jpeg') then
begin
try
aIdHttp.Get(trim(FURL), aMs);
except
end;
if JpgToGif(aMs) then
begin
aMs.SaveToFile(path);
end;
end;

Open in new window



it doesn't save any thing ..

Raise this error

jpeg error #53
So, this is not really a jpeg file as should be... try to save it before conversion... and look for contents with some hex editor....
Avatar of drama22

ASKER

If its not jpeg file header of indy wont read it image its self saved from photoshop as jpg I think there is issue with ms . Because normal gifs saved normally