Bug 702995 - autorotating EPS images
Summary: autorotating EPS images
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Images (show other bugs)
Version: 9.53.3
Hardware: PC All
: P4 major
Assignee: Ray Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-16 11:20 UTC by durharam
Modified: 2020-10-24 19:52 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
this is the EP file, which when converted to png, is auto roteted (843.32 KB, application/postscript)
2020-10-16 11:20 UTC, durharam
Details

Note You need to log in before you can comment on or make changes to this bug.
Description durharam 2020-10-16 11:20:00 UTC
Created attachment 19956 [details]
this is the EP file, which when converted to png, is auto roteted

I have an EPS image which i pass to the ghostscript to be converted to png. image gets converted, but it gets  auto-rotated to 90 degrees. with version 9.52, it works fine and images are not rotated.

this is the command I am passing from windows. the same command is passed to 9,52 also but gives correct output there, and wrong one here.

["C:\Program Files\gs\gs9.53.3\bin\gswin64.exe", -dNOPAUSE, -dEPSFitPage, -g271x38, -r300, -sDEVICE=png16m, -dGraphicsAlphaBits=4, -dBATCH, -sOutputFile=C:\ProgramData\InBetween\Temp\InBetweenClient\IBTemp\eps_13139551606716001602846571945352cccfa-7aad-4817-a8f4-d3d51d8684d0..png, "D:\Trunkcheckout\IBClientServer\bin\..\Projects\myview_2356_VerpackungenPNG\Images\pictures\esylux_logo_pos_cmyk.eps"]. i start the process from java by passing passing these cmdline arguements.
Comment 1 durharam 2020-10-16 11:44:23 UTC
please ignore the previous command which i had entered. this is the correct command:


["C:\Program Files\gs\gs9.52\bin\gswin64.exe", -dNOPAUSE, -dEPSFitPage, -g88x88, -r300, -sDEVICE=png16m, -dGraphicsAlphaBits=4, -dBATCH, -sOutputFile=C:\ProgramData\InBetween\Temp\InBetweenClient\IBTemp\eps_1315788182298900160284840496668bb606f-85b7-4bee-85a9-fa0b2cec6885.png, "D:\Trunkcheckout\IBClientServer\Projects\myview_2356_VerpackungenPNG\Images\piktogramme/eps/2260_Erf_360.eps"]
Comment 2 Ray Johnston 2020-10-16 15:16:50 UTC
With the square page size given in Comment #2 (-g88x88) this page does not
rotate. The logic rotates for best fit when (edx-edy)*(pdx-pdy) is < 0,
where the EPS BoundingBox X and Y sizes are edx and edy, respectively, and
pdx is the page size in X, and pdy is is the page size in Y.

The EPS file has:

%%HiResBoundingBox: 0 0 80.5997 80.6001

which means that the size in X (edx in the above) is very slightly less than
the Y size (edy), thus (edx-edy) will be negative and if the page size has
X size larger than Y size (as with -gg271x38) then (edx-edy) will be positive
and the product will be negative.

With the square page size (-g88x88) the product will always be 0, so it will
not rotate, which is what I observe.

Note that prior to commit 826f4411a that fixes Bug 702607, the logic had some
problems. Note that in that bug there is a subsequent patch (that is NOT yet
accepted) that allows for a flag to disable rotation. You may want to apply
that.
Comment 3 Ken Sharp 2020-10-16 15:32:13 UTC
(In reply to Ray Johnston from comment #2)
> With the square page size given in Comment #2 (-g88x88) this page does not
> rotate.

Did you include -r300 on the command line ? If I do that I can reproduce the problem.
Comment 4 durharam 2020-10-16 16:36:25 UTC
yes. i have added that as to render the image at 300dpi
Comment 5 durharam 2020-10-16 16:51:52 UTC
hello i tried setting the rotationflag to false, but still no luck. but if i change the size of the image, for instance -g113*113, the image does not rotate, also if i st -r300 to some other value like  72dpi -r72, image does not rotate. it only seems to be rotating for -g88*88 at 300 dpi(-r300)
Comment 6 durharam 2020-10-16 16:54:17 UTC
so is there some correlation to dpi and image size, like they rotate at some value thresholds?
Comment 7 Ray Johnston 2020-10-17 20:34:48 UTC
The problem is that the %%BoundingBox scales (and centers) the image using
those values (0 0 81 81) which with -g88x88 sets the CTM to:
    xx: 1.08641982
    xy: 0.000000000
    yx: 0.000000000
    yy: -1.08641982
    tx: -2.38418579e-07
    ty: 88.0000000

Then when the %%HiResBoundingBox is processed, the clippath pathbbox returns a
slightly non-square page size, which can result in inadvertent rotation.

I have a patch to gs_epsf.ps in test that only applies the FitPage scaling,
centering and rotation once.
Comment 8 Ray Johnston 2020-10-24 19:52:15 UTC
Fixed in commit 8313e4f30bef7c50711cd503c3037184a7850d51

Changed to only apply the scaling, centering, and rotation once so we don't
encounter the rounding problems that caused the strange behavior depending on
the device resolution.