gboolean gimp_image_item_list_bounds (GimpImage *image, GList *list, gint *x, gint *y, gint *width, gint *height) { GList *l; gboolean bounds = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (x != 0, FALSE); g_return_val_if_fail (y != 0, FALSE); g_return_val_if_fail (width != 0, FALSE); g_return_val_if_fail (height != 0, FALSE); for (l = list; l; l = g_list_next (l)) { GimpItem *item = l->data; gint tmp_x, tmp_y; gint tmp_w, tmp_h; if (gimp_item_bounds (item, &tmp_x, &tmp_y, &tmp_w, &tmp_h)) { gint off_x, off_y; gimp_item_get_offset (item, &off_x, &off_y); if (bounds) { gimp_rectangle_union (*x, *y, *width, *height, tmp_x + off_x, tmp_y + off_y, tmp_w, tmp_h, x, y, width, height); } else { *x = tmp_x + off_x; *y = tmp_y + off_y; *width = tmp_w; *height = tmp_h; bounds = TRUE; } } } if (! bounds) { *x = 0; *y = 0; *width = gimp_image_get_width (image); *height = gimp_image_get_height (image); } return bounds; }
void gimp_image_resize_to_layers (GimpImage *image, GimpContext *context, GimpProgress *progress) { GList *list; GimpItem *item; gint x, y; gint width, height; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (GIMP_IS_CONTEXT (context)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); list = gimp_image_get_layer_iter (image); if (! list) return; /* figure out starting values */ item = list->data; x = gimp_item_get_offset_x (item); y = gimp_item_get_offset_y (item); width = gimp_item_get_width (item); height = gimp_item_get_height (item); /* Respect all layers */ for (list = g_list_next (list); list; list = g_list_next (list)) { item = list->data; gimp_rectangle_union (x, y, width, height, gimp_item_get_offset_x (item), gimp_item_get_offset_y (item), gimp_item_get_width (item), gimp_item_get_height (item), &x, &y, &width, &height); } gimp_image_resize (image, context, width, height, -x, -y, progress); }