MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Export[..., ImageResolution, ... ImageSize]

  • To: mathgroup at
  • Subject: [mg107108] Re: Export[..., ImageResolution, ... ImageSize]
  • From: Alexey <lehin.p at>
  • Date: Wed, 3 Feb 2010 06:08:32 -0500 (EST)
  • References: <hgq25u$gb8$>

On 22 Dec 2009, 12:06, "Scot Martin" <smar... at> wrote:
> Anyone have insight on this problem with image resolution in version 7?
> SetDirectory@NotebookDirectory[];
> plot = Plot[x, {x, 0, 10}];
> Export["plot.gif",plot,ImageSize->5*72,ImageResolution->300]
> The export command seems to ignore ImageResolution.
> Here is what used to work in V5.2 of Mathematica:
> Export["plot.gif",plot,ImageResolution->300]
> This "plot.gif" in V7 now has the problem that all of the ticks and so forth
> have become very small, i.e., they were not scaled properly. Apparently,
> Mathematica combined ImageSize and ImageResolution by scaling the image to
> (300/72)*5*72, without proportionate magnification of the ticks.  [This was
> not a problem in earlier versions of Mathematica, e.g., V5.2.]
> Here is a messy workaround:
> Export["plot.gif", Magnify[Show[FullGraphics@plot, Options[plot,
> AspectRatio]], 300/72],ImageResolution -> 300]
> My question for the group: Am I missing a simple solution to this problem
> instead of the messy work around?
> Thanks for any help and insight!


The solution for your problem is (code for Mathematica 7.0.1):

$HistoryLength = 0;
plot = Plot[x, {x, 0, 10}]
g = Rasterize[plot, ImageResolution -> 300]
dims = g[[1, 1]] // Dimensions
ggg = Graphics[g[[1]], ImageSize -> dims[[{2, 1}]]];
Export["C:/plot.gif", Image[ggg]]

This problem has already been discussed in this newsgroup. In short,
the explanation is as follows:

1) Graphics has default width 360 pixels and in this way the quality
will be only 360 pixels width even if Raster[] inside Graphics[]
contains much more points. And resizing does not help. This also
directly affects Export[]... :( But Image[] always has true dimensions
and preserves quality. I discussed it in details here:

2) I have not found a perfect way how to change *default* width of
Graphics[] (without using ImageSize). I discussed it here:

3) There are some undocumented functions for working with raster
graphics that may help. See here:

4) I have created a function Raster2Image that converts
Graphics[Raster[]] to Image with preserving quality
(as opposed to Image[Graphics]):

Raster2Image = Image[Part[#, Sequence @@ Position[#, _Raster]
[[1]], 1], ColorSpace -> "RGB"] &;

I also created function fix4Graphics that fixes loosing quality with

fix4Graphics = Append[#, ImageSize -> Reverse[Take[Dimensions
[Part[#, Sequence @@ Position[#, _Raster][[1]], 1]], 2]]] &;

  • Prev by Date: Re: Re: A question about a sphere
  • Next by Date: Re: Re: Re: How to combine graphics
  • Previous by thread: Re: Is this a bug? FromAdjacencyMatrix[]
  • Next by thread: Re: Re: Re: How to combine graphics