4
$\begingroup$

Here's a way to reproduce the issue: export the following picture

Export["a.png", Plot[Sin@x, {x, -5, 5}], ImageSize -> 500, ImageResolution -> 500]
SystemOpen@Directory[]

and paste it into a blank .doc/docx file (either with Ctrl+c, Ctrl+v or the Insert -> Picture in the menu), then you'll see something like

enter image description here

Further check shows the picture isn't lossy compressed, it is just zoomed out to 1 inch wide. Why this happens? Is it a expected behavior?

I'm on v9.0.1, MS Office 2016 64bit, Win10 64bit.

$\endgroup$
  • $\begingroup$ Works as expected on "10.0 for Mac OS X x86 (64-bit) (December 4, 2014)" and MSW for Mac 14.5.8 I understand this behavior is as designed. You can grab a corner and dragging with the mouse the size. $\endgroup$ – user9660 Dec 4 '15 at 13:54
  • $\begingroup$ I'm voting to close this question as off-topic because the question does not concern the technical computing software Mathematica, but is about the office software MS Word $\endgroup$ – Jason B. Dec 4 '15 at 13:57
  • $\begingroup$ @JasonB Well, I don't think so. This strange behavior won't appear if you casually find a picture somewhere and paste it into Word. $\endgroup$ – xzczd Dec 4 '15 at 14:00
  • $\begingroup$ @Lou That would be quite annoying if the size of the image needs to be accurate. $\endgroup$ – xzczd Dec 4 '15 at 14:02
  • $\begingroup$ @xzczd - I see your point. When I import a png I created using the Shutter screenshot program, that is 479 pixels wide and 480 pixels in height, it takes up almost a full page. When I import a picture that I exported in Mathematica, which is 1000 pixels wide and 617 pixels high, it is much smaller. I wonder what is different about the images. $\endgroup$ – Jason B. Dec 4 '15 at 14:07
5
$\begingroup$

The problem here lies in the fact that you have explicitly set the ImageSize variable. When you say ImageSize->1000 you are telling it that you want an image that is 1000 pixels wide. So when you set the resolution, which is measure in pixels per unit distance, to a higher value you are in effect setting the dimensions of the output image smaller.

Take these two outputted files,

Export["a500.png", Plot[Sin@x, {x, -5, 5}], ImageSize -> 1000, 
 ImageResolution -> 500]
Export["a72.png", Plot[Sin@x, {x, -5, 5}], ImageSize -> 1000, 
 ImageResolution -> 72]

On my system "a500.png" is 42.9 kB and "a72.png" is 32.6 kB, but both are around 1000x617 pixels. enter image description here Actually, "a72.png" is 1000x614 pixels, but that doesn't seem enough to account for the different file sizes - so if anyone knows what the extra data is doing, I'd be happy to find out.

Now take the same code, but this time don't explicitly set the ImageSize

Export["b500.png", Plot[Sin@x, {x, -5, 5}], ImageResolution -> 500]
Export["b72.png", Plot[Sin@x, {x, -5, 5}], ImageResolution -> 72]

Now the file "b72.png" is 15.6 kB and "b500.png" is 141.2 kB and has many more pixels,

enter image description here

Here are the images imported into word without any resizing, on the left page is a500 followed by a72, and on the right side is b500 followed by b72.

enter image description here

Edit: Taking from this answer, the following will allow you to export two images, one looking a lot better than the other because it has a higher resolution, but both will have the same dimensions,

Export["c500.png", 
 Plot[Sin@x, {x, -5, 5}, 
  ImageSize -> {72 QuantityMagnitude[Quantity[4, "Inches"]], 
    Automatic}], ImageResolution -> 500]
Export["c72.png", 
 Plot[Sin@x, {x, -5, 5}, 
  ImageSize -> {72 QuantityMagnitude[Quantity[4, "Inches"]], 
    Automatic}], ImageResolution -> 72]

enter image description here

It turns out that the important part is to not give ImageSize as an option to Export but as an option to Plot

$\endgroup$
  • $\begingroup$ I am confused here. I thought ImageSize was in printers points not pixels as you suggest. An Imagesize of 500 should come out at 6.94 inches as there are 72 points in an inch. I have a laptop and several docking stations so my screen resolution can vary. I am not clear how pixels which is about screen resolution comes into this. $\endgroup$ – Hugh Dec 4 '15 at 14:54
  • $\begingroup$ I don't really know, I just saw that when I set ImageSize to a particular value, then I looked at the exported file, it had that many pixels in its horizontal direction. $\endgroup$ – Jason B. Dec 4 '15 at 14:56
  • $\begingroup$ @Hugh - it seems that Export behaves differently depending on whether ImageSize is given directly as an option or as an option to Plot $\endgroup$ – Jason B. Dec 4 '15 at 15:05
  • $\begingroup$ A subtle point. I had not appreciated that there was a difference between usage of ImageSize in Plot and Export. Are the pixels screen pixels or some reference size? Would you get a poor picture because you are using a screen with few pixels? $\endgroup$ – Hugh Dec 4 '15 at 16:30
  • 1
    $\begingroup$ @xzczd, I think so. Take the files a500 and a72 and upload them to regex.info/exif.cgi $\endgroup$ – Jason B. Dec 5 '15 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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