1999-11-01 19:30:49 +03:00
|
|
|
/*
|
|
|
|
* What is this good for? Who wrote it and when?
|
|
|
|
*/
|
|
|
|
|
1998-12-07 20:11:35 +03:00
|
|
|
#include <config.h>
|
|
|
|
#include <gnome.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
static void
|
1999-11-01 19:30:49 +03:00
|
|
|
put_in_metadata (char *dest, char *png_file, char *secure)
|
1998-12-07 20:11:35 +03:00
|
|
|
{
|
|
|
|
int f;
|
|
|
|
struct stat buf;
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
f = open (secure, O_RDONLY);
|
|
|
|
if (!f){
|
|
|
|
printf ("can not open the source file\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat (png_file, &buf) == -1){
|
|
|
|
printf ("can not stat the source file\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
1999-01-27 04:14:57 +03:00
|
|
|
buffer = g_malloc (buf.st_size);
|
1998-12-07 20:11:35 +03:00
|
|
|
if (buffer == NULL){
|
|
|
|
printf ("No memory\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read (f, buffer, buf.st_size) != buf.st_size){
|
|
|
|
printf ("Something is wrong\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gnome_metadata_set (dest, "icon-inline-png", buf.st_size, buffer);
|
|
|
|
|
1999-01-27 04:14:57 +03:00
|
|
|
g_free (buffer);
|
1998-12-07 20:11:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
make_thumbnail (char *filename)
|
|
|
|
{
|
|
|
|
GdkImlibImage *im, *im2;
|
|
|
|
GdkImlibSaveInfo si;
|
|
|
|
|
|
|
|
im = gdk_imlib_load_image (filename);
|
|
|
|
if (!im)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
si.quality = 1;
|
|
|
|
si.scaling = 1;
|
|
|
|
si.xjustification = 0;
|
|
|
|
si.yjustification = 0;
|
|
|
|
si.page_size = 0;
|
|
|
|
si.color = 0;
|
|
|
|
|
|
|
|
if (im->rgb_width > im->rgb_height)
|
|
|
|
im2 = gdk_imlib_clone_scaled_image (im, 48, im->rgb_height * 48 / im->rgb_width);
|
|
|
|
else
|
|
|
|
im2 = gdk_imlib_clone_scaled_image (im, im->rgb_height * 48 / im->rgb_width, 48);
|
|
|
|
|
|
|
|
gdk_imlib_save_image (im2, secure, &si);
|
|
|
|
|
|
|
|
put_in_metadata (filename, secure);
|
|
|
|
|
|
|
|
gdk_imlib_destroy_image (im);
|
|
|
|
gdk_imlib_destroy_image (im2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv [])
|
|
|
|
{
|
|
|
|
int i;
|
1999-11-01 19:30:49 +03:00
|
|
|
char *secure;
|
1998-12-07 20:11:35 +03:00
|
|
|
|
|
|
|
gnome_init ("test", "test", argc, argv);
|
1999-11-01 19:30:49 +03:00
|
|
|
|
|
|
|
secure = tempnam (NULL, "makethumb");
|
|
|
|
i = open (secure, O_RDWR | O_CREAT | O_EXCL, 0600);
|
|
|
|
if (i == -1) {
|
|
|
|
printf( "Someone is playing /tmp games with us\n" );
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
close(i);
|
1998-12-07 20:11:35 +03:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
1999-11-01 19:30:49 +03:00
|
|
|
make_thumbnail (argv [i], secure);
|
1998-12-07 20:11:35 +03:00
|
|
|
|
|
|
|
unlink (secure);
|
|
|
|
return 0;
|
|
|
|
}
|