RSS/Atom feed Twitter
Site is read-only, email is disabled

file-pdf patch

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 6 messages available
Toggle history

Please log in to manage your subscriptions.

6436009.4611247594269618.Ja... 07 Oct 20:27
  file-pdf patch Thomas Frieling 14 Jul 20:00
   file-pdf patch Martin Nordholts 14 Jul 20:06
18807004.4651247594651291.J... 07 Oct 20:27
  file-pdf patch Thomas Frieling 14 Jul 20:04
   file-pdf patch Sven Neumann 14 Jul 22:47
Thomas Frieling
2009-07-14 20:00:33 UTC (over 15 years ago)

file-pdf patch

Hi all!

Just wanted to share a litte patch for file-pdf.c to support a max width/height and a page number as parameters. Maybe someone can clean the code and push it into the next gimp release.

Usage: gimp -i -b '(pdftojpg inputfilename maxWidth maxHeight outputfilename quality radius delta brightness contrast page)' -b '(gimp-quit 0)' Example:
gimp -i -b '(pdftojpg "/tmp/input.pdf" 1000 1800 "/tmp/output.jpg" 0.85 3.5 15 -10 5 3)' -b '(gimp-quit 0)'

Have fun, Thomas

Thomas Frieling
2009-07-14 20:04:38 UTC (over 15 years ago)

file-pdf patch

I guess I also need to copy&past the patch (attachments don't seem to work here...)

So here it is:

*** file-pdf.c 2008-11-20 23:43:49.000000000 +0100 --- file-pdf-patched.c 2009-05-07 16:51:02.000000000 +0200 ***************
*** 264,271 ****

static const GimpParamDef thumb_args[] = {
! { GIMP_PDB_STRING, "filename", "The name of the file to load" }, ! { GIMP_PDB_INT32, "thumb-size", "Preferred thumbnail size" } };

static const GimpParamDef thumb_return_vals[] = --- 264,277 ----

static const GimpParamDef thumb_args[] = {
! { GIMP_PDB_STRING, "filename", "The name of the file to load" }, ! /* start of patched part to define preferred height and width of thumbnail - by Cihan Aksakal, Nils Mull */ ! { GIMP_PDB_INT32, "preferred-width", "Preferred thumbnail width" }, ! { GIMP_PDB_INT32, "preferred-height", "Preferred thumbnail height" }, ! /* end of patched part to define preferred height and width of thumbnail - by Cihan Aksakal, Nils Mull */ ! /* start of patched part to define page number to extract - by Cihan Aksakal, Nils Mull */ ! { GIMP_PDB_INT32, "page-number", "Page Number to extract (Note: 0-Based)" } ! /* end of patched part to define page number to extract - by Cihan Aksakal, Nils Mull */ };

static const GimpParamDef thumb_return_vals[] = ***************
*** 427,513 ****
}
else if (strcmp (name, LOAD_THUMB_PROC) == 0) {
! if (nparams < 2)
! {
status = GIMP_PDB_CALLING_ERROR; ! }
! else
! {
gdouble width = 0; gdouble height = 0; gdouble scale;
gint32 image = -1; GdkPixbuf *pixbuf = NULL;

/* Possibly retrieve last settings */ gimp_get_data (LOAD_PROC, &loadvals);

doc = open_document (param[0].data.d_string, &error);

! if (doc) ! {
! PopplerPage *page = poppler_document_get_page (doc, 0); !
! if (page)
! {
! poppler_page_get_size (page, &width, &height); !
! g_object_unref (page); }

! pixbuf = get_thumbnail (doc, 0, param[1].data.d_int32); g_object_unref (doc); - }
-
- if (pixbuf)
- {
- image = gimp_image_new (gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf), - GIMP_RGB); -
- gimp_image_undo_disable (image); -
- layer_from_pixbuf (image, "thumbnail", 0, pixbuf, 0.0, 1.0); - g_object_unref (pixbuf);

! gimp_image_undo_enable (image); ! gimp_image_clean_all (image); }

! scale = loadvals.resolution / gimp_unit_get_factor (GIMP_UNIT_POINT);

- width *= scale; - height *= scale;
-
- if (image != -1)
- {
- *nreturn_vals = 4;
-
- values[1].type = GIMP_PDB_IMAGE; - values[1].data.d_image = image; - values[2].type = GIMP_PDB_INT32; - values[2].data.d_int32 = width; - values[3].type = GIMP_PDB_INT32; - values[3].data.d_int32 = height; - }
- else
- {
- status = GIMP_PDB_EXECUTION_ERROR; - }
}

! }
! else
! {
status = GIMP_PDB_CALLING_ERROR; }

! if (status != GIMP_PDB_SUCCESS && error) ! {
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING; values[1].data.d_string = error->message; ! }

values[0].data.d_status = status; }
--- 433,568 ----
}
else if (strcmp (name, LOAD_THUMB_PROC) == 0) {
! if (nparams < 2) {
status = GIMP_PDB_CALLING_ERROR; ! } else {
! /* start of patched part to define page number to extract - by Cihan Aksakal, Nils Mull */ gdouble width = 0; gdouble height = 0; gdouble scale;
gint32 image = -1; GdkPixbuf *pixbuf = NULL;

+ /* calculate page number to extract */ + gint32 extractionPageNumber = 0; + if (param[3].data.d_int32 > 0) { + extractionPageNumber = param[3].data.d_int32; + }
/* Possibly retrieve last settings */ gimp_get_data (LOAD_PROC, &loadvals);

doc = open_document (param[0].data.d_string, &error); +
+ /* check whether the document is loaded and contains enough pages to process the extraction of the defined page */ + if (doc && poppler_document_get_n_pages(doc) > extractionPageNumber) { + /* added var extractionPageNumber instead of 0 - now it extracts the defined page */ + PopplerPage *page = poppler_document_get_page (doc, extractionPageNumber); + if (page) {
+ poppler_page_get_size (page, &width, &height); + g_object_unref (page); + }

! /* calculate prefered size */ ! if (param[1].data.d_int32 > 0 && param[2].data.d_int32 > 0) { ! /* calculate preferred width and height */ ! gint32 preferredSize = 0; !
! gint32 bbWidth = param[1].data.d_int32; ! gint32 bbHeight = param[2].data.d_int32; !
! gdouble pWidth = 0;
! gdouble pHeight = 0; !
! /* calculation for image scaling & preferredSize */ ! if (width > height) { ! printf("width > height\n"); ! pWidth = bbWidth;
! pHeight = (gdouble) (pWidth/width) * height; ! printf("%f x %f\n", pWidth, pHeight); ! if (pHeight > bbHeight) { ! printf("pHeight (%f) > bbHeight (%d)\n", pHeight, bbHeight); ! pWidth = (gdouble) (bbHeight/pHeight) * pWidth; // check ! pHeight = bbHeight; ! printf("%f x %f\n", pWidth, pHeight); }
+ } else {
+ printf("width =< height\n"); + pHeight = bbHeight; + pWidth = (gdouble) (pHeight/height) * width; + printf("%f x %f\n", pWidth, pHeight); + if (pWidth > bbWidth) { + printf("pWidth (%f) > bbWidth (%d)\n", pWidth, bbWidth); + pHeight = (gdouble) (bbWidth/pWidth) * pHeight; // check + pWidth = bbWidth; + printf("%f x %f\n", pWidth, pHeight); + }
+ }
+ preferredSize = MAX(pWidth, pHeight);

! /* added var extractionPageNumber instead of 0 - now it extracts the defined page */ ! pixbuf = get_thumbnail (doc, extractionPageNumber, preferredSize); g_object_unref (doc);

! if (pixbuf) { ! image = gimp_image_new (gdk_pixbuf_get_width (pixbuf), ! gdk_pixbuf_get_height (pixbuf), ! GIMP_RGB); !
! gimp_image_undo_disable (image); !
! layer_from_pixbuf (image, "thumbnail", 0, pixbuf, 0.0, 1.0); ! g_object_unref (pixbuf); !
! gimp_image_undo_enable (image); ! gimp_image_clean_all (image); ! }
!
! scale = loadvals.resolution / gimp_unit_get_factor (GIMP_UNIT_POINT); !
! width *= scale;
! height *= scale;
!
! if (image != -1) {
! *nreturn_vals = 4;
!
! values[1].type = GIMP_PDB_IMAGE; ! values[1].data.d_image = image; ! values[2].type = GIMP_PDB_INT32; ! values[2].data.d_int32 = width; ! values[3].type = GIMP_PDB_INT32; ! values[3].data.d_int32 = height; ! } else {
! status = GIMP_PDB_EXECUTION_ERROR; ! }
! } else { /* preferred height and width parameters check failed */ ! /* set error message and status that a file page number violation occured */ ! g_set_error (&error, 0, 0,
! "Could not calculate preferred thumbail height and width (width: '%d', height: '%d' ). Note: Both parameters have to be greater 0. PDF-File: '%s'", ! param[1].data.d_int32, param[2].data.d_int32, gimp_filename_to_utf8 (param[0].data.d_string) ); ! status = GIMP_PDB_EXECUTION_ERROR; }

! } else if (doc) { /* check doc & page number failed */ ! /* set error message and status that a file page number violation occured */ ! g_set_error (&error, 0, 0,
! "Could not extract page-number %d (Note: 0-Based). Documnent has only %d pages. PDF-File: '%s'", ! extractionPageNumber, poppler_document_get_n_pages(doc), gimp_filename_to_utf8 (param[0].data.d_string) ); ! status = GIMP_PDB_EXECUTION_ERROR; ! }
! /* check doc & page number */

} + /* end of patched part to define page number to extract - by Cihan Aksakal, Nils Mull */

! } else { status = GIMP_PDB_CALLING_ERROR; }

! if (status != GIMP_PDB_SUCCESS && error) { *nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING; values[1].data.d_string = error->message; ! }

values[0].data.d_status = status; }

----- Ursprüngliche Mail ----- Von: "Thomas Frieling"
An: gimp-developer@lists.XCF.Berkeley.EDU Gesendet: Dienstag, 14. Juli 2009 20:00:33 GMT +01:00 Amsterdam/Berlin/Bern/Rom/Stockholm/Wien Betreff: file-pdf patch

Hi all!

Just wanted to share a litte patch for file-pdf.c to support a max width/height and a page number as parameters. Maybe someone can clean the code and push it into the next gimp release.

Usage: gimp -i -b '(pdftojpg inputfilename maxWidth maxHeight outputfilename quality radius delta brightness contrast page)' -b '(gimp-quit 0)' Example:
gimp -i -b '(pdftojpg "/tmp/input.pdf" 1000 1800 "/tmp/output.jpg" 0.85 3.5 15 -10 5 3)' -b '(gimp-quit 0)'

Have fun, Thomas

Martin Nordholts
2009-07-14 20:06:31 UTC (over 15 years ago)

file-pdf patch

On 07/14/2009 08:00 PM, Thomas Frieling wrote:

Hi all!

Just wanted to share a litte patch for file-pdf.c to support a max width/height and a page number as parameters. Maybe someone can clean the code and push it into the next gimp release.

Hi!

Please attach this patch to bugzilla in the unified diff format, preferably in the form of a git commit with your name and email address. Thanks!

BR,
Martin

Sven Neumann
2009-07-14 22:47:57 UTC (over 15 years ago)

file-pdf patch

Hi,

On Tue, 2009-07-14 at 20:04 +0200, Thomas Frieling wrote:

I guess I also need to copy&past the patch (attachments don't seem to work here...)

That's why we kindly asked you to open an enhancement request and then attach your patch there. Thanks.

Sven