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
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i tried
it doesn't save any thing ..
Raise this error
jpeg error #53
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;
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;
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....
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
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):