I have generated an image using (for example)

out = Plot[x^2, {x, -2, 0}, PlotLegends -> {x^2}]

and would like to export two versions of that image, one that is 72 points wide and another that is 144 points wide (the numbers don't particularly matter). I have tried

Export[filename, out, ImageSize -> 72]

but that doesn't work - the exported image has the same size as the original one. (This is consistent with the documentation, which says [somewhat confusingly] that While ImageSize changes the display size of an image (on the screen), it does not affect the underlying dimensions (as reported by ImageDimensions). Functions useful for changing the actual dimensions of an Image object include ImageResize, ImageCrop, ImageTrim, and ImagePad. So I guess that makes sense.

Next I tried ImageResize:

Export[filename, ImageResize[out, 72]]

This failed because ImageResize is not applicable to the given object, since its head is Legended rather than Graphics.

Even if I remove the legend (which I really can't do given the application), the result of ImageResize is a very poor image: enter image description here

Is there any way to automate the production of two different size of the same image? (By the way, I previously posted this question, which asked part of this question as well, and never really received an adequate answer.)

  • 2
    $\begingroup$ r1=Show[out, ImageSize -> 100]; r2=Show[out, ImageSize -> 200]. Export both and you will see the difference in their file properties. $\endgroup$
    – Hubble07
    Dec 18 '15 at 19:05
  • $\begingroup$ Umm...wow, do I feel like an idiot. Never thought of Show. That does indeed solve the problem. If you want to post that as an answer, I'll accept it. Thanks. $\endgroup$
    – rogerl
    Dec 18 '15 at 19:30

The exporting can be automated using Table

sizeList = {100, 200, 300};

Table[r[i] = Show[out, ImageSize -> sizeList[[i]]]; 
Export[ToString[i] <> ".jpg", r[i], ImageResolution -> 300], {i,1,Length[sizeList]}];

{r[1], r[2], r[3]}

enter image description here


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.