Krolyxon
Commit d8114e8

Branches

Refs →

nsxivd8114e8

Thumbnail cache file format depending on existance of alpha layer

Use PNG if image has alpha layer, JPG if not. Fixes issue #209
Author
Bert Münnich
Date
2015-07-22 21:08 +0200
Parent
9264a65
Commit
d8114e841c5b5933a655a3ec728cedd37b86d27d

+9 −5

2 files changed

  1. M Makefile +1 −1
  2. M thumbs.c +8 −4
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION := git-20150518
1+VERSION := git-20150722
22
33 PREFIX := /usr/local
44 MANPREFIX := $(PREFIX)/share/man
M thumbs.c View
@@ -48,9 +48,9 @@ char* tns_cache_filepath(const char *filepath)
4848
4949 if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) {
5050 /* don't cache images inside the cache directory! */
51− len = strlen(cache_dir) + strlen(filepath) + 6;
51+ len = strlen(cache_dir) + strlen(filepath) + 2;
5252 cfile = (char*) s_malloc(len);
53− snprintf(cfile, len, "%s/%s.jpg", cache_dir, filepath + 1);
53+ snprintf(cfile, len, "%s/%s", cache_dir, filepath + 1);
5454 }
5555 return cfile;
5656 }
@@ -101,8 +101,12 @@ void tns_cache_write(Imlib_Image im, const char *filepath, bool force)
101101 }
102102 if (err == 0) {
103103 imlib_context_set_image(im);
104− imlib_image_set_format("jpg");
105− imlib_image_attach_data_value("quality", NULL, 90, NULL);
104+ if (imlib_image_has_alpha()) {
105+ imlib_image_set_format("png");
106+ } else {
107+ imlib_image_set_format("jpg");
108+ imlib_image_attach_data_value("quality", NULL, 90, NULL);
109+ }
106110 imlib_save_image_with_error_return(cfile, &err);
107111 }
108112 if (err == 0) {