summaryrefslogtreecommitdiffstats
path: root/src/helper/save-image.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
commitc853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch)
tree7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/helper/save-image.cpp
parentInitial commit. (diff)
downloadinkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.tar.xz
inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.zip
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/helper/save-image.cpp')
-rw-r--r--src/helper/save-image.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/helper/save-image.cpp b/src/helper/save-image.cpp
new file mode 100644
index 0000000..eca667b
--- /dev/null
+++ b/src/helper/save-image.cpp
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "save-image.h"
+#include <glib/gi18n.h>
+#include <string>
+#include "display/cairo-utils.h"
+#include "helper/choose-file.h"
+#include "object/sp-image.h"
+
+namespace Inkscape {
+
+bool save_image(const std::string& fname, const Inkscape::Pixbuf* pixbuf) {
+ if (fname.empty() || !pixbuf) return false;
+
+ Inkscape::Pixbuf image(*pixbuf);
+ auto pix = image.getPixbufRaw(true);
+ GError* error = nullptr;
+ gdk_pixbuf_save(pix, fname.c_str(), "png", &error, nullptr);
+ if (error) {
+ g_warning("Image saving error: %s", error->message);
+ g_error_free(error);
+ return false;
+ }
+ else {
+ return true;
+ }
+}
+
+bool extract_image(Gtk::Window* parent, SPImage* image) {
+ if (!image || !image->pixbuf || !parent) return false;
+
+ std::string current_dir;
+ auto fname = choose_file_save(_("Extract Image"), parent, "image/png", "image.png", current_dir);
+ if (fname.empty()) return false;
+
+ // save image
+ return save_image(fname, image->pixbuf.get());
+}
+
+} // namespace Inkscape