diff src/gtkaccount.c @ 10523:f5c9438982f8

[gaim-migrate @ 11840] This should preserve aspect ratios when scaling buddy icons. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 18 Jan 2005 02:16:48 +0000
parents bec9130b24d2
children f175ff63d571
line wrap: on
line diff
--- a/src/gtkaccount.c	Tue Jan 18 02:11:51 2005 +0000
+++ b/src/gtkaccount.c	Tue Jan 18 02:16:48 2005 +0000
@@ -562,8 +562,8 @@
 			 height < prpl_info->icon_spec.min_height ||
 			 height > prpl_info->icon_spec.max_height))
 		{
-			int new_width = gdk_pixbuf_get_width(pixbuf);
-			int new_height = gdk_pixbuf_get_height(pixbuf);
+			int new_width = width;
+			int new_height = height;
 
 			if(new_width > prpl_info->icon_spec.max_width)
 				new_width = prpl_info->icon_spec.max_width;
@@ -574,6 +574,14 @@
 			else if(new_height < prpl_info->icon_spec.min_height)
 				new_height = prpl_info->icon_spec.min_height;
 
+			/* preserve aspect ratio */
+			if ((double)height * (double)new_width >
+				(double)width * (double)new_height) {
+					new_width = 0.5 + (double)width * (double)new_height / (double)height;
+			} else {
+					new_height = 0.5 + (double)height * (double)new_width / (double)width;
+			}
+
 			scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height,
 					GDK_INTERP_HYPER);
 			g_object_unref(G_OBJECT(pixbuf));
@@ -606,6 +614,9 @@
 			 * FALSE if an error was set. */
 			if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE)
 					break;
+			gaim_debug_warning("buddyicon", "Could not convert to %s: %s\n", prpl_formats[i], error->message);
+			g_error_free(error);
+			error = NULL;
 		}
 		g_strfreev(prpl_formats);
 		if (!error) {