bugGNU Octave - Bugs: bug #49698, Setting PNG output resolution and...

 
 

bug #49698: Setting PNG output resolution and size in print command overwrites resolution

Submitter:  None
Submitted:  Fri 25 Nov 2016 09:08:32 AM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Wont Fix Assigned to:  None
Originator Name:  Wysi Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 03 Mar 2019 06:11:36 PM UTC, comment #4: 

On reviewing the documentation, I am marking this as "Won't Fix".  The resolution '-r' and size '-S' arguments are not intended to be used together for a raster-based output.  If you desire a certain number of pixels in the output, use '-S'.  If you desire a certain size and resolution, then set the figure property "PaperPosition" to the desired size and use -r to then influence how many pixels are used.

Rik <rik5>
Group administrator
Sat 26 Nov 2016 04:06:32 AM UTC, comment #3: 

This probably indicates the fix needs to be devised more carefully and it needs to be tested on multiple operating systems and multiple versions of ghostscript, etc.  On my computer I needed to modify the canvas size in order to get 800x500 output.  On your computer, that was not the case.

Rik <rik5>
Group administrator
Fri 25 Nov 2016 02:40:11 PM UTC, comment #2: 

Thank you. I quickly tested it, the result is as attached: Now resolution is correct, but canvas size is not the original input size.

In my example code below (and on my Windows machine), the original canvas size of [800,500] is changed to

[800,500]/600*72 = [96,60]

Instead, I'd prefer to keep [800,500].


Suggestion: Only change resolution if not specified as input:

E.g.

if ~any(cellfun(@any,strfind(varargin,'-r')))   % add: if '-r' option is set, do not overwrite
        arg_st.ghostscript.resolution = 72;
    end  % add


wysi <wysi>
Fri 25 Nov 2016 12:57:03 PM UTC, comment #1: 

Confirmed.  The attached diff seems to fix the issue for me.

(file #39068)

Rik <rik5>
Group administrator
Fri 25 Nov 2016 09:08:32 AM UTC, original submission:  

Task: Saving a figure to .png as it appears on the screen, using both size and resolution options (e.g. -S800,500, -r600).
Result: While both Options alone work, setting them together overwrites the rsolution with 72.

Example code:

figure(1,'Position',[100,100,800,500]);
plot(randn(100,2))
title('test'); ylabel('y axis'); xlabel('x axis');
pos=get(gcf,'Position');
print('-dpng', 'test.png', '-r600',['-S',num2str(pos(3)),',',num2str(pos(4))]);

The output is of very much lower resolution, probably 72 (cf. below).

The problem may be related to code in the function scripts/plot/util/private/__print_parse_opts__.m, where it says around line 367:

arg_st.ghostscript.resolution = 72;

Simply commenting out this line, the output looks as expected. However, this is probably not the solution for all cases.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #39069:  test.png added by wysi (32KiB - image/png)
file #39068:  printsz.diff added by rik5 (1KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by wysi (Updated the item)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-03 rik5 StatusConfirmed Wont Fix
        Open/ClosedOpen Closed
    2016-11-25 wysi Attached File- Added test.png, #39069
    2016-11-25 rik5 Attached File- Added printsz.diff, #39068
        StatusNone Confirmed
        Release4.0.3 4.2.0
        Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code