TransWikia.com

ImageSize bug in Rasterize

Mathematica Asked by Simon Woods on May 24, 2021

Bug introduced in 8 or earlier and persisting through 11.3.0


In version 11.0.0 I am getting incorrect sizes from Rasterize.
The problem remains in 11.0.1

Rasterize["hi", "Image", ImageSize -> {100, 100}] // ImageDimensions
(* {100, 102} *)

Rasterize["hi", "Graphics", ImageSize -> {100, 100}] // First // First // Dimensions
(* {102, 100, 3} *)

Rasterize["hi", "RasterSize", ImageSize -> {100, 100}]
(* {96, 102} *)

Can anyone confirm this?

I am using Windows 10.

One Answer

According to the documentation the correct option to set the coarseness of the rasterization is RasterSize, whereas ImageSize only controls the size at which the image is displayed.

I'm not sure why I was using ImageSize previously, possibly RasterSize did not behave as advertised in an earlier version, or perhaps I didn't read the documentation carefully enough.

Anyway, in 12.2 everything appears to work as expected:

image = Rasterize["hi", "Image", 
   RasterSize -> {100, 100}, ImageSize -> {50, 50}];

(* displayed size *)
ImageSize /. Options[image]
(* {50, 50} *)

(* actual number of pixels in ImageData *)
ImageDimensions[image]
(* {100, 100} *)

Answered by Simon Woods on May 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP