Re: Fw: PNG Output: Canvas limited to smaller image side?

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu Dec 29 2011 - 16:50:46 MST

Fabricio,

In my experience, NCL constrains you to a square canvas when making
PNG files, and this is not considered a bug, just a limitation. Here
is the recipe that I use to make rectangular (i.e. not square) PNG
files:

1. Set both wkHeight and wkWidth to the same number, the LARGEST
dimension that you need. Add a little extra because NCL normally adds
automatic white space around the edges.

2. Run the NCL script and get a PNG file.

3. Post process with Imagemagick to remove ALL white borders on all
four edges. The following exact command will NOT distort the aspect
ratio of the visible plot, and it will not degrade the visible pixels:

  convert -trim +repage in.png out.png

4. If you need a uniform white border around the image, then
experiment with something like the -margin or -frame options of
Imagemagick. I have not tried this yet. Skip this step if you do not
need this.

5. Now you have a smaller PNG file whose dimensions are controlled by
the most outlying non-white pixels from your original plot.
Therefore, if the visible area in your plot is rectangular, the new
PNG file will also be rectangular.

6. If the new dimensions are not exactly what you want, then go back
to step 1, and change the wkHeight/wkWidth setting in proportion to
the change needed.

If your original plot does not have the correct aspect ratio to make
exactly 1280x720 pixels by this method, than you may have to settle
for a result that fits on one dimension, and is a little smaller on
the other dimension. I have found this quite sufficient for making
PNG files that fit properly into constrained spaces on web pages.

Alternatively, you may wish to just use the -crop option of
Imagemagick, to cut away exactly the right amount of X and Y white
space from the result of step 2. This requires setting pixel counts
manually, but it might be preferable for automating many plots of
exactly the same size. HTH.

--Dave

On Thu, Dec 29, 2011 at 10:53 AM, Heavenly Avenger
<avenger-ncl@avenger.ws> wrote:
> Hello,
>
>     I am having bad times trying to arrange graphs side-by-side on wide
> screen resolution canvas (1280x720). When I set wkHeight to 720 and wkWidth
> to 1280, all usable space by any combination of vpHeightF and vpWidthF
> (inclusive suppressing tem), gsnScale and gsnMaximize is 720x720. If I make
> a 720x1280 (and other different size combinations), the graphs are still
> bound to the smallest of the dimensions.
>     I suspect I can kind of override this problem doing a .ps on a landscape
> page, but I am afraid I will have another hassle to fit the resulting page
> on a 1280x720 image without some major distortion. I could also cut it with
> imagemagick but, I am not sure it is the way NCL was meant to work.
>     After all, is that a known bug? Is there something special one must do
> in order to use all, non-square, canvas size while using the
> ImageWorkstation stuff? This is my first job on NCL (a 300-line long script
> to interpret and graph CSV files), so I must be missing something.
>     To reproduce the error all you may need to do is create a non-square
> .png and try and plot a graph into the canvas. The more difference in sides
> the clearer is the problem. I tried also distributing in panels
> (gsn_panel()) and direct plotting of a single graph (gsn_csm_xy()).
>     As a side question, I see there is not support to write .png’s with
> transparent background. Is there any plan to implementing this in the
> future? I am also aware of the solution using imagemagick+ps to get good
> results. The problem would be the shell dependency and control of output
> image wid/hei.
>
> Thanks in advance,
> Fabricio Murta
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Dec 29 16:50:58 2011

This archive was generated by hypermail 2.1.8 : Wed Jan 04 2012 - 10:18:09 MST