View Issue Details

IDProjectCategoryView StatusLast Update
0017617ScribusScripterpublic2025-09-09 19:56
Reporterhugowett Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.7.1.svn 
Fixed in Version1.7.1.svn 
Summary0017617: Add python function for getting the actual PPI of an image
DescriptionWhen automating image mounting it's very useful to get the actual PPI out of scribus, this patch adds the function getImagePpi([frame_name]) that returns a integer tuple containing the horizontal and vertical PPI.
TagsNo tags attached.
Attached Files
0001-script-getter-for-actual-image-PPI.patch (3,563 bytes)   
From fe24c9cce04684adeae75813ce0cf28b80878fda Mon Sep 17 00:00:00 2001
From: Hugo Wetterberg <hugo@wetterberg.nu>
Date: Thu, 4 Sep 2025 17:48:31 +0200
Subject: [PATCH] script getter for actual image PPI

---
 scribus/plugins/scriptplugin/cmdgetprop.cpp   | 19 +++++++++++++++++++
 scribus/plugins/scriptplugin/cmdgetprop.h     | 11 +++++++++++
 scribus/plugins/scriptplugin/scriptplugin.cpp |  1 +
 3 files changed, 31 insertions(+)

diff --git scribus/plugins/scriptplugin/cmdgetprop.cpp scribus/plugins/scriptplugin/cmdgetprop.cpp
index dd44aca96..a16f75afa 100644
--- scribus/plugins/scriptplugin/cmdgetprop.cpp
+++ scribus/plugins/scriptplugin/cmdgetprop.cpp
@@ -379,6 +379,25 @@ PyObject *scribus_getimagescale(PyObject* /* self */, PyObject* args)
 	return Py_BuildValue("(ff)", item->imageXScale() / 72.0 * item->pixm.imgInfo.xres, item->imageYScale() / 72.0 * item->pixm.imgInfo.yres);
 }
 
+PyObject *scribus_getimageppi(PyObject* /* self */, PyObject* args)
+{
+	PyESString name;
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", name.ptr()))
+		return nullptr;
+	if (!checkHaveDocument())
+		return nullptr;
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name.c_str()));
+	if (item == nullptr)
+		return nullptr;
+	if (!item->isImageFrame())
+	{
+		PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	return Py_BuildValue("(ii)", qRound(72.0 / item->imageXScale()), qRound(72.0 / item->imageYScale()));
+}
+
 PyObject *scribus_getimagefile(PyObject* /* self */, PyObject* args)
 {
 	PyESString name;
diff --git scribus/plugins/scriptplugin/cmdgetprop.h scribus/plugins/scriptplugin/cmdgetprop.h
index 1e39a0593..bceb0a284 100644
--- scribus/plugins/scriptplugin/cmdgetprop.h
+++ scribus/plugins/scriptplugin/cmdgetprop.h
@@ -277,6 +277,17 @@ Returns a (x, y) tuple containing the scaling values of the image frame\n\
 /*! Returns image scale of the object */
 PyObject *scribus_getimagescale(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getimageppi__doc__,
+	QT_TR_NOOP("getImagePpi([\"name\"]) -> (x,y)\n\
+\n\
+Returns a (x, y) tuple containing the actual PPI of the image frame\n\
+\"name\".  If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Returns actual image ppi of the object */
+PyObject *scribus_getimageppi(PyObject * /*self*/, PyObject* args);
+
+
 /*! docstring */
 PyDoc_STRVAR(scribus_getposition__doc__,
 QT_TR_NOOP("getPosition([\"name\"]) -> (x,y)\n\
diff --git scribus/plugins/scriptplugin/scriptplugin.cpp scribus/plugins/scriptplugin/scriptplugin.cpp
index 20f2b34cb..30743afe1 100644
--- scribus/plugins/scriptplugin/scriptplugin.cpp
+++ scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -381,6 +381,7 @@ PyMethodDef scribus_methods[] = {
 	{ "getImagePreviewResolution", scribus_getimagepreviewresolution, METH_VARARGS, tr(scribus_getimagepreviewresolution__doc__)},
 	{ "getImagePageCount", scribus_getimagepagecount, METH_VARARGS, tr(scribus_getimagepagecount__doc__)},
 	{ "getImageScale", scribus_getimagescale, METH_VARARGS, tr(scribus_getimagescale__doc__)},
+	{ "getImagePpi", scribus_getimageppi, METH_VARARGS, tr(scribus_getimageppi__doc__)},
 	{ "getInfo", (PyCFunction) scribus_getinfo, METH_VARARGS, tr(scribus_getinfo__doc__)},
 	{ "getItemPageNumber", scribus_getitempagenumber, METH_VARARGS, tr(scribus_getitempagenumber__doc__)},
 	{ "getLastLinkedFrame", scribus_getlastlinkedframe, METH_VARARGS, tr(scribus_getlastlinkedframe__doc__)},
-- 
2.51.0

PatchYes

Activities

jghali

2025-09-07 17:47

administrator   ~0053008

Your patch has been applied, thanks!

hugowett

2025-09-08 11:17

reporter   ~0053012

That was quick, thanks jghali!

Issue History

Date Modified Username Field Change
2025-09-05 05:26 hugowett New Issue
2025-09-05 05:26 hugowett File Added: 0001-script-getter-for-actual-image-PPI.patch
2025-09-06 08:55 ale Summary Add python function for getting the actual PPI of an image => [PATCH] Add python function for getting the actual PPI of an image
2025-09-07 17:47 jghali Assigned To => jghali
2025-09-07 17:47 jghali Status new => resolved
2025-09-07 17:47 jghali Resolution open => fixed
2025-09-07 17:47 jghali Fixed in Version => 1.7.1.svn
2025-09-07 17:47 jghali Note Added: 0053008
2025-09-07 17:51 jghali Summary [PATCH] Add python function for getting the actual PPI of an image => Add python function for getting the actual PPI of an image
2025-09-08 11:17 hugowett Note Added: 0053012
2025-09-09 19:56 cbradney Status resolved => closed