I export 2D and 3D plots to PNG images using the export command. I can set ImageSize->{xsize,ysize}
or RasterSize->{xsize,ysize}
as an option for export. To me it looks like these commands have the same effect. Is there any practical difference between the two when exporting to PNG?
1 Answer
You may first generate the rasterized image in Mma with specific RasterSize and ImageSize, and then export the already generated image as PNG or whatever.
When you do this, the RasterSize controls the image quality, while the ImageSize fixes its geometrical size. For example, let us vary the RasterSize by keeping the ImageSize constant:
Column@Table[
Rasterize[
Plot[Sin[x], {x, 0, 2 \[Pi]},
PlotLabel -> Row[{Style["RasterSize=", 14], Style[sz, 12]}]],
ImageSize -> 200, RasterSize -> sz], {sz, {50, 100, 300, 500}}]
Let us now keep the RasterSize constant and vary the ImageSize:
Row@Table[
Rasterize[
Plot[Sin[x], {x, 0, 2 \[Pi]},
PlotLabel -> Row[{Style["ImageSize=", 12], Style[sz, 12]}]],
ImageSize -> sz, RasterSize -> 200], {sz, {100, 200, 300}}]
One concludes that each size of the image requires its own RasterSize to garantee the image quality.
Have fun!
-
$\begingroup$ Does this also control the image size in printer points and raster size in pixels for an exported png? $\endgroup$ Commented Jan 27, 2021 at 17:32
-
-
$\begingroup$ Many thanks Alexei, that's very helpful! $\endgroup$– 220284Commented Jan 27, 2021 at 17:49
-
$\begingroup$ @David Keith By definition the option RasterSize determines pixel width and size. $\endgroup$ Commented Jan 27, 2021 at 18:17
ImageResolution -> 300
in myExport
command. $\endgroup$