Skip to content

Commit

Permalink
Added support to showimage for saving images in BMP and JPEG format
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 5, 2017
1 parent 53f44ac commit 95c62d6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion showimage.c
Expand Up @@ -109,7 +109,16 @@ int main(int argc, char *argv[])
if ( saveFile ) {
SDL_Surface *surface = IMG_Load(argv[i]);
if (surface) {
if ( IMG_SavePNG(surface, saveFile) < 0 ) {
int result;
const char *ext = SDL_strrchr(saveFile, '.');
if ( ext && SDL_strcasecmp(ext, ".bmp") == 0 ) {
result = SDL_SaveBMP(surface, saveFile);
} else if ( ext && SDL_strcasecmp(ext, ".jpg") == 0 ) {
result = IMG_SaveJPG(surface, saveFile, 90);
} else {
result = IMG_SavePNG(surface, saveFile);
}
if ( result < 0 ) {
fprintf(stderr, "Couldn't save %s: %s\n", saveFile, SDL_GetError());
}
} else {
Expand Down

0 comments on commit 95c62d6

Please sign in to comment.