From fa15206ba57301ca4daeda40605effaadb082280 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:51:49 +0200 Subject: [PATCH] Add resize_image script function --- src/gfx/generated_image.cpp | 13 +++++++++++++ src/gfx/generated_image.hpp | 15 +++++++++++++++ src/script/functions/image.cpp | 8 ++++++++ .../drupal/mse-drupal-modules/highlight.inc | 3 ++- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/gfx/generated_image.cpp b/src/gfx/generated_image.cpp index 8d0ef742..2c1f32c4 100644 --- a/src/gfx/generated_image.cpp +++ b/src/gfx/generated_image.cpp @@ -304,6 +304,19 @@ bool EnlargeImage::operator == (const GeneratedImage& that) const { && border_size == that2->border_size; } +// ----------------------------------------------------------------------------- : ResizeImage + +Image ResizeImage::generate(const Options& opt) const { + Image img = image->generate(opt); + return resample(img, width, height); +} +bool ResizeImage::operator == (const GeneratedImage& that) const { + const ResizeImage* that2 = dynamic_cast(&that); + return that2 && *image == *that2->image + && width == that2->width + && height == that2->height; +} + // ----------------------------------------------------------------------------- : CropImage Image CropImage::generate(const Options& opt) const { diff --git a/src/gfx/generated_image.hpp b/src/gfx/generated_image.hpp index d1e78221..ef53dff7 100644 --- a/src/gfx/generated_image.hpp +++ b/src/gfx/generated_image.hpp @@ -287,6 +287,21 @@ private: double border_size; }; +// ----------------------------------------------------------------------------- : ResizeImage + +/// Resize an image by resampling it +class ResizeImage : public SimpleFilterImage { +public: + inline ResizeImage(const GeneratedImageP& image, int width, int height) + : SimpleFilterImage(image), width(max(1, width)), height(max(1, height)) + {} + Image generate(const Options& opt) const override; + bool operator == (const GeneratedImage& that) const override; +private: + int width; + int height; +}; + // ----------------------------------------------------------------------------- : CropImage /// Crop an image at a certain point, to a certain size diff --git a/src/script/functions/image.cpp b/src/script/functions/image.cpp index 23951556..787484ac 100644 --- a/src/script/functions/image.cpp +++ b/src/script/functions/image.cpp @@ -134,6 +134,13 @@ SCRIPT_FUNCTION(enlarge) { return make_intrusive(input, border_size); } +SCRIPT_FUNCTION(resize_image) { + SCRIPT_PARAM_C(GeneratedImageP, input); + SCRIPT_PARAM(int, width); + SCRIPT_PARAM(int, height); + return make_intrusive(input, width, height); +} + SCRIPT_FUNCTION(crop) { SCRIPT_PARAM_C(GeneratedImageP, input); SCRIPT_PARAM(int, width); @@ -253,6 +260,7 @@ void init_script_image_functions(Context& ctx) { ctx.setVariable(_("invert_image"), script_invert_image); ctx.setVariable(_("recolor_image"), script_recolor_image); ctx.setVariable(_("enlarge"), script_enlarge); + ctx.setVariable(_("resize_image"), script_resize_image); ctx.setVariable(_("crop"), script_crop); ctx.setVariable(_("flip_horizontal"), script_flip_horizontal); ctx.setVariable(_("flip_vertical"), script_flip_vertical); diff --git a/tools/website/drupal/mse-drupal-modules/highlight.inc b/tools/website/drupal/mse-drupal-modules/highlight.inc index 2c9f908d..26dae510 100644 --- a/tools/website/drupal/mse-drupal-modules/highlight.inc +++ b/tools/website/drupal/mse-drupal-modules/highlight.inc @@ -71,7 +71,7 @@ $built_in_functions = array( 'exclusive_choice' =>'', 'require_exclusive_choice'=>'', 'remove_choice' =>'', - // images + // images 'linear_blend' =>'', 'masked_blend' =>'', 'combine_blend' =>'', @@ -81,6 +81,7 @@ $built_in_functions = array( 'saturate' =>'', 'invert_image' =>'', 'recolor_image' =>'', + 'resize_image' =>'', 'enlarge' =>'', 'crop' =>'', 'flip_horizontal' =>'',