mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 01:43:24 +00:00
config: Add options to auto-scale imported layers
If enabled in Preferences, any image that's dragged into an existing canvas (or explicitly opened as a layer) will be scaled to fit the current canvas size.
This commit is contained in:
parent
93b4dbbbcd
commit
1f370f19b5
5 changed files with 77 additions and 1 deletions
|
@ -112,6 +112,7 @@ enum
|
||||||
PROP_IMPORT_PROMOTE_FLOAT,
|
PROP_IMPORT_PROMOTE_FLOAT,
|
||||||
PROP_IMPORT_PROMOTE_DITHER,
|
PROP_IMPORT_PROMOTE_DITHER,
|
||||||
PROP_IMPORT_ADD_ALPHA,
|
PROP_IMPORT_ADD_ALPHA,
|
||||||
|
PROP_IMPORT_RESIZE_LAYERS,
|
||||||
PROP_IMPORT_RAW_PLUG_IN,
|
PROP_IMPORT_RAW_PLUG_IN,
|
||||||
PROP_EXPORT_FILE_TYPE,
|
PROP_EXPORT_FILE_TYPE,
|
||||||
PROP_EXPORT_COLOR_PROFILE,
|
PROP_EXPORT_COLOR_PROFILE,
|
||||||
|
@ -724,6 +725,13 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
|
||||||
FALSE,
|
FALSE,
|
||||||
GIMP_PARAM_STATIC_STRINGS);
|
GIMP_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_IMPORT_RESIZE_LAYERS,
|
||||||
|
"import-resize-layers",
|
||||||
|
"Import resize layers",
|
||||||
|
IMPORT_RESIZE_LAYERS_BLURB,
|
||||||
|
TRUE,
|
||||||
|
GIMP_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
GIMP_CONFIG_PROP_PATH (object_class, PROP_IMPORT_RAW_PLUG_IN,
|
GIMP_CONFIG_PROP_PATH (object_class, PROP_IMPORT_RAW_PLUG_IN,
|
||||||
"import-raw-plug-in",
|
"import-raw-plug-in",
|
||||||
"Import raw plug-in",
|
"Import raw plug-in",
|
||||||
|
@ -1142,6 +1150,9 @@ gimp_core_config_set_property (GObject *object,
|
||||||
case PROP_IMPORT_ADD_ALPHA:
|
case PROP_IMPORT_ADD_ALPHA:
|
||||||
core_config->import_add_alpha = g_value_get_boolean (value);
|
core_config->import_add_alpha = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_IMPORT_RESIZE_LAYERS:
|
||||||
|
core_config->import_resize_layers = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
case PROP_IMPORT_RAW_PLUG_IN:
|
case PROP_IMPORT_RAW_PLUG_IN:
|
||||||
g_free (core_config->import_raw_plug_in);
|
g_free (core_config->import_raw_plug_in);
|
||||||
core_config->import_raw_plug_in = g_value_dup_string (value);
|
core_config->import_raw_plug_in = g_value_dup_string (value);
|
||||||
|
@ -1408,6 +1419,9 @@ gimp_core_config_get_property (GObject *object,
|
||||||
case PROP_IMPORT_ADD_ALPHA:
|
case PROP_IMPORT_ADD_ALPHA:
|
||||||
g_value_set_boolean (value, core_config->import_add_alpha);
|
g_value_set_boolean (value, core_config->import_add_alpha);
|
||||||
break;
|
break;
|
||||||
|
case PROP_IMPORT_RESIZE_LAYERS:
|
||||||
|
g_value_set_boolean (value, core_config->import_resize_layers);
|
||||||
|
break;
|
||||||
case PROP_IMPORT_RAW_PLUG_IN:
|
case PROP_IMPORT_RAW_PLUG_IN:
|
||||||
g_value_set_string (value, core_config->import_raw_plug_in);
|
g_value_set_string (value, core_config->import_raw_plug_in);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -96,6 +96,7 @@ struct _GimpCoreConfig
|
||||||
gboolean import_promote_float;
|
gboolean import_promote_float;
|
||||||
gboolean import_promote_dither;
|
gboolean import_promote_dither;
|
||||||
gboolean import_add_alpha;
|
gboolean import_add_alpha;
|
||||||
|
gboolean import_resize_layers;
|
||||||
gchar *import_raw_plug_in;
|
gchar *import_raw_plug_in;
|
||||||
GimpExportFileType export_file_type;
|
GimpExportFileType export_file_type;
|
||||||
gboolean export_color_profile;
|
gboolean export_color_profile;
|
||||||
|
|
|
@ -223,6 +223,10 @@ _("When promoting imported images to floating point precision, also add " \
|
||||||
#define IMPORT_ADD_ALPHA_BLURB \
|
#define IMPORT_ADD_ALPHA_BLURB \
|
||||||
_("Add an alpha channel to all layers of imported images.")
|
_("Add an alpha channel to all layers of imported images.")
|
||||||
|
|
||||||
|
#define IMPORT_RESIZE_LAYERS_BLURB \
|
||||||
|
_("Resize imported layers to fit the existing image, retaining the " \
|
||||||
|
"imported layers' aspect ratio.")
|
||||||
|
|
||||||
#define IMPORT_RAW_PLUG_IN_BLURB \
|
#define IMPORT_RAW_PLUG_IN_BLURB \
|
||||||
_("Which plug-in to use for importing raw digital camera files.")
|
_("Which plug-in to use for importing raw digital camera files.")
|
||||||
|
|
||||||
|
|
|
@ -1591,6 +1591,11 @@ prefs_dialog_new (Gimp *gimp,
|
||||||
_("_Add an alpha channel to imported images"),
|
_("_Add an alpha channel to imported images"),
|
||||||
GTK_BOX (vbox2));
|
GTK_BOX (vbox2));
|
||||||
|
|
||||||
|
button = prefs_check_button_add (object, "import-resize-layers",
|
||||||
|
_("Resi_ze imported layers to fit the "
|
||||||
|
"existing canvas"),
|
||||||
|
GTK_BOX (vbox2));
|
||||||
|
|
||||||
grid = prefs_grid_new (GTK_CONTAINER (vbox2));
|
grid = prefs_grid_new (GTK_CONTAINER (vbox2));
|
||||||
button = prefs_enum_combo_box_add (object, "color-profile-policy", 0, 0,
|
button = prefs_enum_combo_box_add (object, "color-profile-policy", 0, 0,
|
||||||
_("Color _profile policy:"),
|
_("Color _profile policy:"),
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "gegl/gimp-babl.h"
|
#include "gegl/gimp-babl.h"
|
||||||
|
|
||||||
|
#include "config/gimpcoreconfig.h"
|
||||||
|
|
||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
#include "core/gimpcontext.h"
|
#include "core/gimpcontext.h"
|
||||||
#include "core/gimpdocumentlist.h"
|
#include "core/gimpdocumentlist.h"
|
||||||
|
@ -630,7 +632,57 @@ file_open_layers (Gimp *gimp,
|
||||||
|
|
||||||
if (layers)
|
if (layers)
|
||||||
{
|
{
|
||||||
gchar *basename;
|
GimpCoreConfig *config = dest_image->gimp->config;
|
||||||
|
gchar *basename;
|
||||||
|
|
||||||
|
/* Scale imported layers to fit existing canvas.
|
||||||
|
* Adapted from ofnut's ofn-autoscale-layer.py */
|
||||||
|
if (config->import_resize_layers)
|
||||||
|
{
|
||||||
|
GList *list;
|
||||||
|
gint image_width;
|
||||||
|
gint image_height;
|
||||||
|
gdouble image_ratio;
|
||||||
|
|
||||||
|
image_width = gimp_image_get_width (dest_image);
|
||||||
|
image_height = gimp_image_get_height (dest_image);
|
||||||
|
|
||||||
|
image_ratio = (gdouble) image_width / (gdouble) image_height;
|
||||||
|
|
||||||
|
for (list = layers; list; list = g_list_next (list))
|
||||||
|
{
|
||||||
|
gdouble layer_ratio;
|
||||||
|
gint layer_width;
|
||||||
|
gint layer_height;
|
||||||
|
gint resized_width;
|
||||||
|
gint resized_height;
|
||||||
|
|
||||||
|
layer_width = gimp_item_get_width (GIMP_ITEM (list->data));
|
||||||
|
layer_height = gimp_item_get_height (GIMP_ITEM (list->data));
|
||||||
|
|
||||||
|
layer_ratio = (gdouble) layer_width / (gdouble) layer_height;
|
||||||
|
|
||||||
|
if (layer_ratio > image_ratio)
|
||||||
|
{
|
||||||
|
resized_width = image_width;
|
||||||
|
resized_height = image_width / layer_ratio;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resized_width = image_height * layer_ratio;
|
||||||
|
resized_height = image_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
gimp_item_scale_by_origin (GIMP_ITEM (list->data),
|
||||||
|
resized_width, resized_height,
|
||||||
|
config->interpolation_type,
|
||||||
|
progress, FALSE);
|
||||||
|
gimp_item_set_offset (GIMP_ITEM (list->data),
|
||||||
|
(image_width / resized_width) / 2,
|
||||||
|
(image_height / resized_height) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
||||||
file_open_convert_items (dest_image, basename, layers);
|
file_open_convert_items (dest_image, basename, layers);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue