Szybki resizer obrazków wykorzystujący GdkPixbuf

scaler.c

#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#define MID_WIDTH 1024
#define SMALL_WIDTH 120

int main(int argc, char **argv)
{
GdkPixbuf * pb, *s_pb, *m_pb;
int width, height, m_height, s_height;

g_type_init();
pb = gdk_pixbuf_new_from_file(argv[1], NULL);
width = gdk_pixbuf_get_width(pb);
height = gdk_pixbuf_get_height(pb);
m_height = (int)(1.0 * height * MID_WIDTH / width);
s_height = (int)(1.0 * height * SMALL_WIDTH / width);

s_pb = gdk_pixbuf_scale_simple(pb,SMALL_WIDTH,s_height,GDK_INTERP_BILINEAR);
m_pb = gdk_pixbuf_scale_simple(pb,MID_WIDTH,m_height,GDK_INTERP_BILINEAR);

g_object_unref(pb);

gdk_pixbuf_save(m_pb,argv[2],"jpeg",NULL,"quality", "75", NULL);
g_object_unref(m_pb);
gdk_pixbuf_save(s_pb,argv[3],"jpeg",NULL,"quality", "75", NULL);
g_object_unref(s_pb);

return 0;
}

Makefile


all:
gcc scaler.c -o scaler `pkg-config --cflags --libs gtk+-2.0 gdk-pixbuf-2.0

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *