9
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ I tested on MMA 11, Ubuntu 15.10 64 bits, it returns {100,100}, {100,100,3} but {94, 89}. $\endgroup$
    – anderstood
    Aug 10, 2016 at 19:55
  • $\begingroup$ Win 7 V11 : {100, 101}, {101, 100, 3}, {94, 101}. V10.4 {100, 100}, {100, 100, 3}, {98, 86} $\endgroup$
    – Kuba
    Aug 10, 2016 at 20:24
  • $\begingroup$ I'd report this to Wolfram wolfram.com/support/contact/email/?topic=Technical $\endgroup$
    – ktm
    Aug 10, 2016 at 21:26
  • $\begingroup$ Reported to Wolfram, case number 3685431 $\endgroup$ Aug 11, 2016 at 7:52
  • 1
    $\begingroup$ @Szabolcs, I only noticed it in 11 because some previously working code became broken. Alexey Popkov added the edit "introduced in 8" so I assume it goes back at least that far. $\endgroup$ Oct 18, 2017 at 19:51

1 Answer 1

4
$\begingroup$

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} *)
$\endgroup$
2
  • $\begingroup$ I wonder if there's anyone who can check versions 12 and 12.1 to see if this got fixed in those versions... $\endgroup$ Jan 2, 2021 at 16:23
  • $\begingroup$ I get the correct behavior in version 12.1.1 $\endgroup$
    – tad
    Jan 2, 2021 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.