Bug 43393 - pdftoppm scale-to-x with correct aspect-ratio
Summary: pdftoppm scale-to-x with correct aspect-ratio
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: utils (show other bugs)
Version: unspecified
Hardware: All All
: medium enhancement
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-30 14:23 UTC by Krystian Sikora
Modified: 2012-02-28 02:14 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
fix aspect ratio (920 bytes, patch)
2012-02-25 01:36 UTC, Adrian Johnson
Details | Splinter Review
allow -1 to mean aspect ratio is preserved (1.95 KB, patch)
2012-02-27 02:48 UTC, Adrian Johnson
Details | Splinter Review
document that -scale-to preserves aspect ratio (983 bytes, patch)
2012-02-27 02:49 UTC, Adrian Johnson
Details | Splinter Review

Description Krystian Sikora 2011-11-30 14:23:11 UTC
I'm trying to use pdftoppm to scale my pdfs to width 800 with correct aspect ratio but I noticed that pdftoppm -scale-to-x doesn't handle aspect ratio at all and stretches the image.
My solution was to use pdfinfo to get the size and calculate correct scale-to box which worked well until I needed to deal with pdfs with wrong meta data, for example mediabox and pagesize swapped, width is actually height and vice versa.

If I don't specify any parameters or use -scale-to parameter the output is correct. If -scale-to parameter would accept two sizes -scale-to=x,y then I could use 800,100000 or something similar, it would be very handy to be able to scale to fixed with and maintain aspect ratio whether it would be done with -scale-to-x parameter alone or with extended version of -scale-to parameter or event introduce new parameter.
Comment 1 Adrian Johnson 2012-02-25 01:36:31 UTC
Created attachment 57626 [details] [review]
fix aspect ratio

When only one of -scale-to-x or -scale-to-y is used the other should be set based on the aspect ratio. The attached patch fixes this.
Comment 2 Albert Astals Cid 2012-02-25 07:16:47 UTC
To be honest i'm not convinced by that patch.

The manual option clearly says
       -scale-to-x number
              Scales each page horizontally to fit in scale-to-x pixels.

Does not mention it will change the y pixels when i did not ask for it.
Comment 3 Adrian Johnson 2012-02-25 14:22:45 UTC
The -scale-to option also does not do what the man page says.

   -scale-to number
          Scales each page to fit in scale-to*scale-to pixel box.

It says it will scale to the same number of pixel in each direction. What the code does is use the scale-to size for the longest side and sets the other side based on the aspect ratio.
Comment 4 Krystian Sikora 2012-02-25 14:34:50 UTC
Albert: this option is really useless in most cases as it will stretch or narrow the image and destroy it's aspect ratio.
In my opinion it will fit more use cases following aspect ratio.

I think that we could also change the parameter description in man page to state that it will follow aspect ratio.

Also new option could be introduced, for example --keep-aspect-ratio that when used would have the effect of Adrian's patch.
Comment 5 Albert Astals Cid 2012-02-26 11:39:15 UTC
Note: The fact that in your opinion an option is useless means nothing, you are not the only one using pdftoppm. I'm sure that thre is someone using it somewhere and when you change the behaviour it's me as the maintainer that is going to be blamed, not you ;-)

@Adrian : Let's fix it then ;-)

My suggestion:
 * Update pdftoppm manage to mention that scale-to-x keeps aspect ratio by default
 * Make it so that if you pass -1 as one of the scaleXorScaleY parameters means it will maintain the aspect ratio if the other one is specified and put it on the manpage.

What you guys think?
Comment 6 Krystian Sikora 2012-02-26 12:13:22 UTC
I like your suggestion as it adds required functionality without breaking backwards compatibility.
Comment 7 Adrian Johnson 2012-02-27 02:48:38 UTC
Created attachment 57706 [details] [review]
allow -1 to mean aspect ratio is preserved
Comment 8 Adrian Johnson 2012-02-27 02:49:50 UTC
Created attachment 57707 [details] [review]
document that -scale-to preserves aspect ratio

If these two patches are accepted I will update pdftocairo to work the same way.
Comment 9 Albert Astals Cid 2012-02-27 15:32:45 UTC
Looks good to me, please commit :-)
Comment 10 Adrian Johnson 2012-02-28 02:14:41 UTC
pushed


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.