| 1 |
/* |
| 2 |
Copyright © 2011 Christian Persch |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU Lesser General Public |
| 6 |
License as published by the Free Software Foundation; either |
| 7 |
version 2.1 of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This library is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public |
| 15 |
License along with this library; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <locale.h> |
| 20 |
|
| 21 |
#include <glib.h> |
| 22 |
#include <gdk-pixbuf/gdk-pixbuf.h> |
| 23 |
|
| 24 |
int |
| 25 |
main (int argc, char **argv) |
| 26 |
{ |
| 27 |
GOptionContext *context; |
| 28 |
int width = -1; |
| 29 |
int height = -1; |
| 30 |
char **args = NULL; |
| 31 |
GdkPixbuf *pixbuf = NULL; |
| 32 |
GError *error = NULL; |
| 33 |
int ret = 1; |
| 34 |
|
| 35 |
GOptionEntry options_table[] = { |
| 36 |
{ "width", 'w', 0, G_OPTION_ARG_INT, &width, |
| 37 |
"width [optional; defaults to the SVG's width]", "WIDTH" }, |
| 38 |
{ "height", 'h', 0, G_OPTION_ARG_INT, &height, |
| 39 |
"height [optional; defaults to the SVG's height]", "HEIGHT" }, |
| 40 |
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, "INPUT-FILE OUTPUT-FILE" }, |
| 41 |
{ NULL } |
| 42 |
}; |
| 43 |
|
| 44 |
setlocale(LC_ALL, ""); |
| 45 |
|
| 46 |
/* Use the locally built rsvg loader, not the system one */ |
| 47 |
g_setenv ("GDK_PIXBUF_MODULE_FILE", "./gdk-pixbuf.loaders", TRUE); |
| 48 |
|
| 49 |
context = g_option_context_new ("- Pixbuf Test Loader"); |
| 50 |
g_option_context_add_main_entries (context, options_table, NULL); |
| 51 |
g_option_context_parse (context, &argc, &argv, &error); |
| 52 |
g_option_context_free (context); |
| 53 |
if (error) |
| 54 |
goto done; |
| 55 |
|
| 56 |
if (args == NULL || g_strv_length (args) != 2) { |
| 57 |
g_printerr ("Need to specify input and output filenames\n"); |
| 58 |
goto done; |
| 59 |
} |
| 60 |
|
| 61 |
pixbuf = gdk_pixbuf_new_from_file_at_size (args[0], width, height, &error); |
| 62 |
if (pixbuf == NULL) |
| 63 |
goto done; |
| 64 |
|
| 65 |
if (!gdk_pixbuf_save (pixbuf, args[1], "png", &error, NULL)) |
| 66 |
goto done; |
| 67 |
|
| 68 |
/* Success! */ |
| 69 |
ret = 0; |
| 70 |
|
| 71 |
done: |
| 72 |
|
| 73 |
if (error) { |
| 74 |
g_printerr ("Error: %s\n", error->message); |
| 75 |
g_error_free (error); |
| 76 |
} |
| 77 |
|
| 78 |
if (pixbuf) |
| 79 |
g_object_unref (pixbuf); |
| 80 |
|
| 81 |
g_strfreev (args); |
| 82 |
|
| 83 |
return ret; |
| 84 |
} |