Reading this post I opted for resizing an image by 1px to stop content-smuggling attacks:
Image Uploading - security issues
But for some reason transparent gifs come out with a black background. This is the code:
Bitmap FullsizeImage = (Bitmap)System.Drawing.Image.FromStream(OriginalFile);
//FullsizeImage.MakeTransparent(Color.Transparent);
int NewWidth = FullsizeImage.Width - 1;
int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
Bitmap CroppedImage = new Bitmap(NewWidth, NewHeight);
Graphics g = Graphics.FromImage(CroppedImage);
g.DrawImage(FullsizeImage, new Rectangle(0, 0, FullsizeImage.Width, FullsizeImage.Height));
CroppedImage.Save(ImagePath, FullsizeImage.RawFormat);
g.Dispose();
CroppedImage.Dispose();
FullsizeImage.Dispose();
I tried using FullsizeImage.MakeTransparent(Color.Transparent) but that transforms the image into a png and I want to keep the original format.
My final intention is to avoid a posible attack, so any idea on how to do this in a different way rather than resizing? Or anyone has a code that actually resizes transparent gifs by keeping the format?